routes.tsx 1.7 KB

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