routes.tsx 1.9 KB

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