import React, { lazy, Suspense } from 'react'; import { createBrowserRouter } from 'react-router-dom'; import type { RouteObject } from 'react-router-dom'; import { useTranslation } from 'react-i18next'; // 🔥 所有组件全部改为懒加载 const VideoMonitorPage = lazy(() => import('../pages/VideoMonitorPage')); const AIDiagnosisPage = lazy(() => import('../pages/AIAnalysis')); const CleanOptimizationPage = lazy(() => import('../pages/CleanOptimization')); const WorkOrderPage = lazy(() => import('../pages/WorkOrder')); const ReportCenterPage = lazy(() => import('../pages/ReportCenter')); const RealTimeMonitorPage = lazy(() => import('../pages/RealTimeMonitor')); const Agri = lazy(() => import('../pages/Agri')); const Layout = lazy(() => import('../components/Layout')); const ProtectedRoute = lazy(() => import('../components/ProtectedRoute')); const Login = lazy(() => import('../pages/Login')); const Home = lazy(() => import('../pages/Home')); const Video = lazy(() => import('../pages/Video')); const Alerts = lazy(() => import('../pages/Alerts')); const Downloads = lazy(() => import('../pages/Downloads')); const Roles = lazy(() => import('../pages/Roles')); const Users = lazy(() => import('../pages/Users')); const MenuList = lazy(() => import('../components/SystemSetting/MenuList')); const Organization = lazy(() => import('../components/SystemSetting/Organization')); const StationManage = lazy(() => import('../components/SystemSetting/StationManage')); const SystemSetting = lazy(() => import('../pages/SystemSetting')); const Profile = lazy(() => import('../pages/Profile')); const DeviceStatus = lazy(() => import('../components/devices/DeviceStatusPage')); const WayLineTask = lazy(() => import('../components/devices/WayLinePage')); const RobotTask = lazy(() => import('../components/devices/RobotTaskPage')); const DevicesOverview = lazy(() => import('../components/devices/DeviceOverviewPage')); const BasicSettings = lazy(() => import('../components/SystemSetting/BasicSettings')); const UserRolePage = lazy(() => import('../components/SystemSetting/UserPage')); const DeviceAccessPage = lazy(() => import('../components/SystemSetting/DeviceAccessPage')); const OnlineUserPage = lazy(() => import('../components/SystemSetting/OnlineUser')); const DeviceManagementPage = lazy(() => import('../components/SystemSetting/DeviceManagement')); const SystemMaintenancePage = lazy(() => import('../components/SystemSetting/SystemMaintain')); const LogManagement = lazy(() => import('../components/SystemSetting/LogManagement')); const VideoManagement = lazy(() => import('../components/SystemSetting/VideoManagement')); //const ErrorManagement = lazy(() => import('../components/SystemSetting/ErrorManagement')); //const AlarmSettingsManagement = lazy(() => import('../components/SystemSetting/AlarmSettingsManagement')); //const WorkOrderSettingsManagement = lazy(() => import('../components/SystemSetting/WorkOrderSettingsManagement')); // 加载中动画 function PageFallback() { return (
); } // 占位页(国际化) const NoticePolicyPlaceholder = () => { const { t } = useTranslation(); return (

{t('router.noticePolicy')}

); }; const DataSafetyPlaceholder = () => { const { t } = useTranslation(); return (

{t('router.dataSafety')}

); }; const ModuleDeveloping = () => { const { t } = useTranslation(); return (
🚧

{t('router.moduleDeveloping')}

); }; // ====================== 全部懒加载的路由配置 ====================== const routes: RouteObject[] = [ { path: '/login', element: ( }> ), }, { element: ( }> ), children: [ { element: ( }> ), children: [ { index: true, element: ( }> ) }, { path: 'overview', element: ( }> ) }, { path: 'devices/overview', element: ( }> ) }, { path: 'devices/status', element: ( }> ) }, { path: 'devices/wayLineTask', element: ( }> ) }, { path: 'devices/robotTask', element: ( }> ) }, { path: 'video', element: ( }> ) }, { path: 'RealtimeMonitor', element: ( }> ) }, { path: 'monitor', element: ( }> ) }, { path: 'agri', element: ( }> ) }, { path: 'alerts/all', element: ( }> ) }, { path: 'AIanalysis', element: ( }> ) }, { path: 'clean', element: ( }> ) }, { path: 'task', element: ( }> ) }, { path: 'table', element: ( }> ) }, { path: 'systemSetting', element: ( }> ), children: [ { index: true, element: }> }, { path: 'basic', element: }> }, { path: 'User', element: }> }, { path: 'menu', element: }> }, { path: 'org', element: }> }, { path: 'site', element: }> }, { path: 'notice', element: }> }, { path: 'deviceAccess', element: }> }, { path: 'dataSafety', element: }> }, { path: 'systemMaintenance', element: }> }, { path: 'monitor', element: }> }, { path: 'devices', element: }> }, { path: 'log', element: }> }, { path: 'videoManage', element: }> }, ] }, { path: 'downloads', element: ( }> ) }, { path: 'manage/users', element: ( }> ) }, { path: 'manage/roles', element: ( }> ) }, { path: 'manage/menuList', element: ( }> ) }, { path: 'organization', element: ( }> ) }, { path: 'station', element: ( }> ) }, { path: 'system', element: ( }> ) }, { path: 'profile', element: ( }> ) }, { path: '*', element: , }, ], }, ], }, ]; export const router = createBrowserRouter(routes);