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 {node}; } const routes: RouteObject[] = [ { path: '/', element: , children: [ { index: true, element: withSuspense() }, { path: 'inbounds', element: withSuspense() }, { path: 'clients', element: withSuspense() }, { path: 'nodes', element: withSuspense() }, { path: 'settings', element: withSuspense() }, { path: 'xray', element: withSuspense() }, { path: 'api-docs', element: withSuspense() }, ], }, ]; 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(), });