routes.tsx 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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: 'api-docs', element: withSuspense(<ApiDocsPage />) },
  30. ],
  31. },
  32. ];
  33. function computeBasename() {
  34. const raw = (typeof window !== 'undefined' && window.X_UI_BASE_PATH) || '/';
  35. const trimmed = raw.replace(/\/+$/, '');
  36. return `${trimmed}/panel`;
  37. }
  38. export const router = createBrowserRouter(routes, {
  39. basename: computeBasename(),
  40. });