Add a new route #29406
Replies: 1 comment
-
@xiaoqufengdi Hello there! I'm here to assist you with your Superset issue. I can help you solve bugs, answer questions, and even guide you to become a contributor. Let's work together to resolve your concern. To add a new route to Superset and make it work like other single-page applications, follow these steps:
Here is an example of how to add a new route: import { lazy } from 'react';
// Import the new component using lazy
const NewComponent = lazy(
() => import(/* webpackChunkName: "NewComponent" */ 'src/pages/NewComponent'),
);
export const routes: Routes = [
// ... existing routes
{
path: '/new/route/',
Component: NewComponent,
},
// ... other routes
];
if (isFeatureEnabled(FeatureFlag.TaggingSystem)) {
routes.push({
path: '/superset/all_entities/',
Component: AllEntities,
});
routes.push({
path: '/superset/tags/',
Component: Tags,
});
}
const frontEndRoutes = routes
.map(r => r.path)
.reduce(
(acc, curr) => ({
...acc,
[curr]: true,
}),
{},
);
export function isFrontendRoute(path?: string) {
if (path) {
const basePath = path.split(/[?#]/)[0]; // strip out query params and link bookmarks
return !!frontEndRoutes[basePath];
}
return false;
} In this example, a new route Additionally, ensure that the new route is integrated into the main application component. Here is an example of how the routes are used in import React, { Suspense, useEffect } from 'react';
import { hot } from 'react-hot-loader/root';
import {
BrowserRouter as Router,
Switch,
Route,
useLocation,
} from 'react-router-dom';
import { bindActionCreators } from 'redux';
import { GlobalStyles } from 'src/GlobalStyles';
import ErrorBoundary from 'src/components/ErrorBoundary';
import Loading from 'src/components/Loading';
import Menu from 'src/features/home/Menu';
import getBootstrapData from 'src/utils/getBootstrapData';
import ToastContainer from 'src/components/MessageToasts/ToastContainer';
import setupApp from 'src/setup/setupApp';
import setupPlugins from 'src/setup/setupPlugins';
import { routes, isFrontendRoute } from 'src/views/routes';
import { Logger, LOG_ACTIONS_SPA_NAVIGATION } from 'src/logger/LogUtils';
import setupExtensions from 'src/setup/setupExtensions';
import { logEvent } from 'src/logger/actions';
import { store } from 'src/views/store';
import { RootContextProviders } from './RootContextProviders';
import { ScrollToTop } from './ScrollToTop';
setupApp();
setupPlugins();
setupExtensions();
const bootstrapData = getBootstrapData();
let lastLocationPathname: string;
const boundActions = bindActionCreators({ logEvent }, store.dispatch);
const LocationPathnameLogger = () => {
const location = useLocation();
useEffect(() => {
// This will log client side route changes for single page app user navigation
boundActions.logEvent(LOG_ACTIONS_SPA_NAVIGATION, {
path: location.pathname,
});
// reset performance logger timer start point to avoid soft navigation
// cause dashboard perf measurement problem
if (lastLocationPathname && lastLocationPathname !== location.pathname) {
Logger.markTimeOrigin();
}
lastLocationPathname = location.pathname;
}, [location.pathname]);
return <></>;
};
const App = () => (
<Router>
<ScrollToTop />
<LocationPathnameLogger />
<RootContextProviders>
<GlobalStyles />
<Menu
data={bootstrapData.common.menu_data}
isFrontendRoute={isFrontendRoute}
/>
<Switch>
{routes.map(({ path, Component, props = {}, Fallback = Loading }) => (
<Route path={path} key={path}>
<Suspense fallback={<Fallback />}>
<ErrorBoundary>
<Component user={bootstrapData.user} {...props} />
</ErrorBoundary>
</Suspense>
</Route>
))}
</Switch>
<ToastContainer />
</RootContextProviders>
</Router>
);
export default hot(App); This ensures that your new route is properly integrated and behaves like other single-page applications within Superset [1][2]. |
Beta Was this translation helpful? Give feedback.
-
Bug description
How to add a new route to superset?
How to reproduce the bug
When I add a new route at the front end(superset-frontend), I can't find it as long as I refresh the global route.
How does it work like other single-page apps?
Screenshots/recordings
No response
Superset version
4.0.1
Python version
3.9
Node version
18 or greater
Browser
Chrome
Additional context
No response
Checklist
Beta Was this translation helpful? Give feedback.
All reactions