diff --git a/src/RootApp.tsx b/src/RootApp.tsx index afd9831474..bf5f4f76a5 100644 --- a/src/RootApp.tsx +++ b/src/RootApp.tsx @@ -1,4 +1,3 @@ -import loadable from '@loadable/component'; import { History } from '@remix-run/router'; import { QueryClientProvider } from '@tanstack/react-query'; import { ReactQueryDevtools } from '@tanstack/react-query-devtools'; @@ -8,21 +7,14 @@ import { ApiProvider } from 'hooks/useApi'; import { WebConfigProvider } from 'hooks/useWebConfig'; import { queryClient } from 'utils/query/queryClient'; -const StableAppRouter = loadable(() => import('./apps/stable/AppRouter')); -const RootAppRouter = loadable(() => import('./RootAppRouter')); +import RootAppRouter from './RootAppRouter'; const RootApp = ({ history }: Readonly<{ history: History }>) => { - const layoutMode = localStorage.getItem('layout'); - const isExperimentalLayout = layoutMode === 'experimental'; - return ( - {isExperimentalLayout ? - : - - } + diff --git a/src/RootAppRouter.tsx b/src/RootAppRouter.tsx index 1fc2293703..ae683fe946 100644 --- a/src/RootAppRouter.tsx +++ b/src/RootAppRouter.tsx @@ -4,21 +4,26 @@ import React from 'react'; import { RouterProvider, createHashRouter, - Outlet + Outlet, + useLocation } from 'react-router-dom'; +import { DASHBOARD_APP_PATHS, DASHBOARD_APP_ROUTES } from 'apps/dashboard/routes/routes'; import { EXPERIMENTAL_APP_ROUTES } from 'apps/experimental/routes/routes'; +import { STABLE_APP_ROUTES } from 'apps/stable/routes/routes'; import AppHeader from 'components/AppHeader'; import Backdrop from 'components/Backdrop'; import { useLegacyRouterSync } from 'hooks/useLegacyRouterSync'; -import { DASHBOARD_APP_ROUTES } from 'apps/dashboard/routes/routes'; import UserThemeProvider from 'themes/UserThemeProvider'; +const layoutMode = localStorage.getItem('layout'); +const isExperimentalLayout = layoutMode === 'experimental'; + const router = createHashRouter([ { element: , children: [ - ...EXPERIMENTAL_APP_ROUTES, + ...(isExperimentalLayout ? EXPERIMENTAL_APP_ROUTES : STABLE_APP_ROUTES), ...DASHBOARD_APP_ROUTES ] } @@ -35,10 +40,14 @@ export default function RootAppRouter({ history }: Readonly<{ history: History}> * NOTE: The app will crash if these get removed from the DOM. */ function RootAppLayout() { + const location = useLocation(); + const isNewLayoutPath = Object.values(DASHBOARD_APP_PATHS) + .some(path => location.pathname.startsWith(`/${path}`)); + return ( - + diff --git a/src/apps/experimental/routes/routes.tsx b/src/apps/experimental/routes/routes.tsx index 47e0a9f7f5..beff0629ac 100644 --- a/src/apps/experimental/routes/routes.tsx +++ b/src/apps/experimental/routes/routes.tsx @@ -6,11 +6,13 @@ import ConnectionRequired from 'components/ConnectionRequired'; import { toAsyncPageRoute } from 'components/router/AsyncRoute'; import { toViewManagerPageRoute } from 'components/router/LegacyRoute'; import { toRedirectRoute } from 'components/router/Redirect'; -import AppLayout from '../AppLayout'; import { ASYNC_USER_ROUTES } from './asyncRoutes'; import { LEGACY_PUBLIC_ROUTES, LEGACY_USER_ROUTES } from './legacyRoutes'; import VideoPage from './video'; +import loadable from '@loadable/component'; + +const AppLayout = loadable(() => import('../AppLayout')); export const EXPERIMENTAL_APP_ROUTES: RouteObject[] = [ { diff --git a/src/apps/stable/AppRouter.tsx b/src/apps/stable/AppRouter.tsx deleted file mode 100644 index 40b5c2aa39..0000000000 --- a/src/apps/stable/AppRouter.tsx +++ /dev/null @@ -1,43 +0,0 @@ -import { History } from '@remix-run/router'; -import React from 'react'; -import { Outlet, RouterProvider, createHashRouter, useLocation } from 'react-router-dom'; - -import { useLegacyRouterSync } from 'hooks/useLegacyRouterSync'; -import { STABLE_APP_ROUTES } from './routes/routes'; -import Backdrop from 'components/Backdrop'; -import AppHeader from 'components/AppHeader'; -import { DASHBOARD_APP_PATHS, DASHBOARD_APP_ROUTES } from 'apps/dashboard/routes/routes'; -import UserThemeProvider from 'themes/UserThemeProvider'; - -const router = createHashRouter([{ - element: , - children: [ - ...STABLE_APP_ROUTES, - ...DASHBOARD_APP_ROUTES - ] -}]); - -export default function StableAppRouter({ history }: Readonly<{ history: History }>) { - useLegacyRouterSync({ router, history }); - - return ; -} - -/** - * Layout component that renders legacy components required on all pages. - * NOTE: The app will crash if these get removed from the DOM. - */ -function StableAppLayout() { - const location = useLocation(); - const isNewLayoutPath = Object.values(DASHBOARD_APP_PATHS) - .some(path => location.pathname.startsWith(`/${path}`)); - - return ( - - - - - - - ); -}