Files
3x-ui/frontend/src/routes.tsx
T
25f2002654 14c9bdff89 refactor(frontend): read the panel's navigation from one route manifest (#6922)
The router, the sidebar, the page titles and the command palette each kept
their own list of the panel's pages, so a page added to one could go
missing from another without any test noticing. They all read
src/routes/panelRoutes.tsx now, and a contract test holds the manifest to
the router, the translation bundle and the palette keywords.

The unused useZodForm helper goes, and CONTRIBUTING, frontend/CLAUDE.md and
the frontend README describe the useForm + rhfZodValidate pattern the
panel's forms actually use.
2026-10-24 20:48:31 +02:00

49 lines
1.2 KiB
TypeScript

import { Suspense } from 'react';
import { createBrowserRouter, type RouteObject } from 'react-router';
import { Spin } from 'antd';
import PanelLayout from '@/layouts/PanelLayout';
import { PANEL_ROUTES } from '@/routes/panelRoutes';
function withSuspense(node: React.ReactNode) {
return (
<Suspense
fallback={
<div
style={{
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
minHeight: '60vh',
}}
>
<Spin size="large" />
</div>
}
>
{node}
</Suspense>
);
}
export const routes: RouteObject[] = [
{
path: '/',
element: <PanelLayout />,
children: PANEL_ROUTES.map((route) => {
const element = withSuspense(<route.component />);
return route.path === '/' ? { index: true, element } : { path: route.path.slice(1), element };
}),
},
];
function computeBasename() {
const raw = (typeof window !== 'undefined' && window.X_UI_BASE_PATH) || '/';
const trimmed = raw.replace(/\/+$/, '');
return `${trimmed}/panel`;
}
export const router = createBrowserRouter(routes, {
basename: computeBasename(),
});