1
0

routes.tsx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { lazy, Suspense } from 'react';
  2. import { createBrowserRouter, type RouteObject } from 'react-router-dom';
  3. import PanelLayout from '@/layouts/PanelLayout';
  4. const IndexPage = lazy(() => import('@/pages/index/IndexPage'));
  5. const InboundsPage = lazy(() => import('@/pages/inbounds/InboundsPage'));
  6. const ClientsPage = lazy(() => import('@/pages/clients/ClientsPage'));
  7. const NodesPage = lazy(() => import('@/pages/nodes/NodesPage'));
  8. const SettingsPage = lazy(() => import('@/pages/settings/SettingsPage'));
  9. const XrayPage = lazy(() => import('@/pages/xray/XrayPage'));
  10. const ApiDocsPage = lazy(() => import('@/pages/api-docs/ApiDocsPage'));
  11. function withSuspense(node: React.ReactNode) {
  12. return <Suspense fallback={null}>{node}</Suspense>;
  13. }
  14. const routes: RouteObject[] = [
  15. {
  16. path: '/',
  17. element: <PanelLayout />,
  18. children: [
  19. { index: true, element: withSuspense(<IndexPage />) },
  20. { path: 'inbounds', element: withSuspense(<InboundsPage />) },
  21. { path: 'clients', element: withSuspense(<ClientsPage />) },
  22. { path: 'nodes', element: withSuspense(<NodesPage />) },
  23. { path: 'settings', element: withSuspense(<SettingsPage />) },
  24. { path: 'xray', element: withSuspense(<XrayPage />) },
  25. { path: 'api-docs', element: withSuspense(<ApiDocsPage />) },
  26. ],
  27. },
  28. ];
  29. function computeBasename() {
  30. const raw = (typeof window !== 'undefined' && window.X_UI_BASE_PATH) || '/';
  31. const trimmed = raw.replace(/\/+$/, '');
  32. return `${trimmed}/panel`;
  33. }
  34. export const router = createBrowserRouter(routes, {
  35. basename: computeBasename(),
  36. });