mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-06-05 20:54:14 +00:00
43 lines
1.6 KiB
TypeScript
43 lines
1.6 KiB
TypeScript
|
|
import { lazy, Suspense } from 'react';
|
||
|
|
import { createBrowserRouter, type RouteObject } from 'react-router-dom';
|
||
|
|
|
||
|
|
import PanelLayout from '@/layouts/PanelLayout';
|
||
|
|
|
||
|
|
const IndexPage = lazy(() => import('@/pages/index/IndexPage'));
|
||
|
|
const InboundsPage = lazy(() => import('@/pages/inbounds/InboundsPage'));
|
||
|
|
const ClientsPage = lazy(() => import('@/pages/clients/ClientsPage'));
|
||
|
|
const NodesPage = lazy(() => import('@/pages/nodes/NodesPage'));
|
||
|
|
const SettingsPage = lazy(() => import('@/pages/settings/SettingsPage'));
|
||
|
|
const XrayPage = lazy(() => import('@/pages/xray/XrayPage'));
|
||
|
|
const ApiDocsPage = lazy(() => import('@/pages/api-docs/ApiDocsPage'));
|
||
|
|
|
||
|
|
function withSuspense(node: React.ReactNode) {
|
||
|
|
return <Suspense fallback={null}>{node}</Suspense>;
|
||
|
|
}
|
||
|
|
|
||
|
|
const routes: RouteObject[] = [
|
||
|
|
{
|
||
|
|
path: '/',
|
||
|
|
element: <PanelLayout />,
|
||
|
|
children: [
|
||
|
|
{ index: true, element: withSuspense(<IndexPage />) },
|
||
|
|
{ path: 'inbounds', element: withSuspense(<InboundsPage />) },
|
||
|
|
{ path: 'clients', element: withSuspense(<ClientsPage />) },
|
||
|
|
{ path: 'nodes', element: withSuspense(<NodesPage />) },
|
||
|
|
{ path: 'settings', element: withSuspense(<SettingsPage />) },
|
||
|
|
{ path: 'xray', element: withSuspense(<XrayPage />) },
|
||
|
|
{ path: 'api-docs', element: withSuspense(<ApiDocsPage />) },
|
||
|
|
],
|
||
|
|
},
|
||
|
|
];
|
||
|
|
|
||
|
|
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(),
|
||
|
|
});
|