1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00
jellyfin-web/src/RootAppRouter.tsx

56 lines
1.7 KiB
TypeScript
Raw Normal View History

import { History } from '@remix-run/router';
import React from 'react';
import {
RouterProvider,
2023-10-06 20:45:37 -07:00
createHashRouter,
Outlet,
useLocation
} from 'react-router-dom';
import { EXPERIMENTAL_APP_ROUTES } from 'apps/experimental/routes/routes';
2023-10-06 20:45:37 -07:00
import AppHeader from 'components/AppHeader';
import Backdrop from 'components/Backdrop';
import { useLegacyRouterSync } from 'hooks/useLegacyRouterSync';
import { DASHBOARD_APP_PATHS, DASHBOARD_APP_ROUTES } from 'apps/dashboard/routes/routes';
import UserThemeProvider from 'themes/UserThemeProvider';
import { STABLE_APP_ROUTES } from 'apps/stable/routes/routes';
const layoutMode = localStorage.getItem('layout');
const isExperimentalLayout = layoutMode === 'experimental';
const router = createHashRouter([
2023-10-06 20:45:37 -07:00
{
element: <RootAppLayout />,
children: [
...(isExperimentalLayout ? EXPERIMENTAL_APP_ROUTES : STABLE_APP_ROUTES),
2023-10-06 20:45:37 -07:00
...DASHBOARD_APP_ROUTES
]
}
]);
2023-10-06 20:45:37 -07:00
export default function RootAppRouter({ history }: Readonly<{ history: History}>) {
useLegacyRouterSync({ router, history });
return <RouterProvider router={router} />;
}
2023-10-06 20:45:37 -07: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() {
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 (
<UserThemeProvider>
2023-10-06 20:45:37 -07:00
<Backdrop />
<AppHeader isHidden={isExperimentalLayout || isNewLayoutPath} />
2023-10-06 20:45:37 -07:00
<Outlet />
</UserThemeProvider>
2023-10-06 20:45:37 -07:00
);
}