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

60 lines
1.7 KiB
TypeScript
Raw Normal View History

import React from 'react';
import {
RouterProvider,
2023-10-06 20:45:37 -07:00
createHashRouter,
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';
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';
import { createRouterHistory } from 'components/router/routerHistory';
import UserThemeProvider from 'themes/UserThemeProvider';
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),
2024-09-13 10:17:29 -04:00
...DASHBOARD_APP_ROUTES,
{
path: '!/*',
Component: BangRedirect
}
2023-10-06 20:45:37 -07:00
]
}
]);
export const history = createRouterHistory(router);
export default function RootAppRouter() {
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
);
}