2023-10-06 20:26:00 -07:00
|
|
|
|
|
|
|
import React from 'react';
|
2023-10-06 20:09:19 -07:00
|
|
|
import {
|
|
|
|
RouterProvider,
|
2023-10-06 20:45:37 -07:00
|
|
|
createHashRouter,
|
2024-07-16 16:30:29 -04:00
|
|
|
Outlet,
|
|
|
|
useLocation
|
2023-10-06 20:09:19 -07:00
|
|
|
} from 'react-router-dom';
|
2023-10-06 20:26:00 -07:00
|
|
|
|
2024-07-24 15:12:10 -04:00
|
|
|
import { DASHBOARD_APP_PATHS, DASHBOARD_APP_ROUTES } from 'apps/dashboard/routes/routes';
|
2023-10-06 20:26:00 -07:00
|
|
|
import { EXPERIMENTAL_APP_ROUTES } from 'apps/experimental/routes/routes';
|
2024-07-24 15:12:10 -04:00
|
|
|
import { STABLE_APP_ROUTES } from 'apps/stable/routes/routes';
|
2023-10-06 20:45:37 -07:00
|
|
|
import AppHeader from 'components/AppHeader';
|
|
|
|
import Backdrop from 'components/Backdrop';
|
2024-09-13 10:17:29 -04:00
|
|
|
import BangRedirect from 'components/router/BangRedirect';
|
2024-07-24 15:12:10 -04:00
|
|
|
import { createRouterHistory } from 'components/router/routerHistory';
|
2024-05-26 10:27:08 -04:00
|
|
|
import UserThemeProvider from 'themes/UserThemeProvider';
|
2024-07-16 16:30:29 -04:00
|
|
|
|
|
|
|
const layoutMode = localStorage.getItem('layout');
|
|
|
|
const isExperimentalLayout = layoutMode === 'experimental';
|
2023-10-06 20:26:00 -07:00
|
|
|
|
|
|
|
const router = createHashRouter([
|
2023-10-06 20:45:37 -07:00
|
|
|
{
|
|
|
|
element: <RootAppLayout />,
|
|
|
|
children: [
|
2024-07-16 16:30:29 -04:00
|
|
|
...(isExperimentalLayout ? EXPERIMENTAL_APP_ROUTES : STABLE_APP_ROUTES),
|
2024-09-13 10:17:29 -04:00
|
|
|
...DASHBOARD_APP_ROUTES,
|
|
|
|
{
|
|
|
|
path: '!/*',
|
|
|
|
Component: BangRedirect
|
|
|
|
}
|
2023-10-06 20:45:37 -07:00
|
|
|
]
|
|
|
|
}
|
2023-10-06 20:26:00 -07:00
|
|
|
]);
|
|
|
|
|
2024-07-24 15:12:10 -04:00
|
|
|
export const history = createRouterHistory(router);
|
2023-10-06 20:26:00 -07:00
|
|
|
|
2024-07-24 15:12:10 -04:00
|
|
|
export default function RootAppRouter() {
|
2023-10-06 20:26:00 -07:00
|
|
|
return <RouterProvider router={router} />;
|
|
|
|
}
|
2023-10-06 20:45:37 -07:00
|
|
|
|
2024-01-26 16:21:46 -05:00
|
|
|
/**
|
|
|
|
* Layout component that renders legacy components required on all pages.
|
|
|
|
* NOTE: The app will crash if these get removed from the DOM.
|
|
|
|
*/
|
2023-10-06 20:45:37 -07:00
|
|
|
function RootAppLayout() {
|
2024-07-16 16:30:29 -04:00
|
|
|
const location = useLocation();
|
|
|
|
const isNewLayoutPath = Object.values(DASHBOARD_APP_PATHS)
|
|
|
|
.some(path => location.pathname.startsWith(`/${path}`));
|
|
|
|
|
2023-10-06 20:45:37 -07:00
|
|
|
return (
|
2024-05-26 10:27:08 -04:00
|
|
|
<UserThemeProvider>
|
2023-10-06 20:45:37 -07:00
|
|
|
<Backdrop />
|
2024-07-16 16:30:29 -04:00
|
|
|
<AppHeader isHidden={isExperimentalLayout || isNewLayoutPath} />
|
2023-10-06 20:45:37 -07:00
|
|
|
|
|
|
|
<Outlet />
|
2024-05-26 10:27:08 -04:00
|
|
|
</UserThemeProvider>
|
2023-10-06 20:45:37 -07:00
|
|
|
);
|
|
|
|
}
|