import { createBrowserRouter, Navigate } from 'react-router-dom'; import { lazy, Suspense } from 'react'; import { Spin } from 'antd'; import Login from '../pages/Login'; import BasicLayout from '../layouts/BasicLayout'; import { useSelector } from 'react-redux'; import { RootState } from '../store'; // 加中组件 const LoadingComponent = () => (
); // 路由守卫 const PrivateRoute = ({ children }: { children: React.ReactNode }) => { const token = useSelector((state: RootState) => state.user.token); if (!token) { return ; } return <>{children}; }; // 懒加载组件 const Dashboard = lazy(() => import('../pages/Dashboard')); const User = lazy(() => import('../pages/System/User')); const Role = lazy(() => import('../pages/System/Role')); const Menu = lazy(() => import('../pages/System/Menu')); const Department = lazy(() => import('../pages/System/Department')); const X6Test = lazy(() => import('../pages/X6Test')); const WorkflowDefinitionList = lazy(() => import('../pages/Workflow/Definition')); const WorkflowDesign = lazy(() => import('../pages/Workflow/Definition/Design')); const WorkflowInstance = lazy(() => import('../pages/Workflow/Instance')); const WorkflowMonitor = lazy(() => import('../pages/Workflow/Monitor')); const LogStreamPage = lazy(() => import('../pages/LogStream')); const NodeDesign = lazy(() => import('../pages/Workflow/NodeDesign')); const NodeDesignForm = lazy(() => import('../pages/Workflow/NodeDesign/Design')); const ProjectGroupList = lazy(() => import('../pages/Deploy/ProjectGroup/List')); const ApplicationList = lazy(() => import('../pages/Deploy/Application/List')); const EnvironmentList = lazy(() => import('../pages/Deploy/Environment/List')); const DeploymentConfigList = lazy(() => import('../pages/Deploy/Deployment/List')); const JenkinsList = lazy(() => import('../pages/Jenkins/List')); const External = lazy(() => import('../pages/Deploy/External')); // 创建路由 const router = createBrowserRouter([ { path: '/login', element: }, { path: '/', element: ( ), children: [ { path: '', element: }, { path: 'dashboard', element: ( }> ) }, { path: 'deploy', children: [ { path: 'project-group', element: }> }, { path: 'applications', element: }> }, { path: 'environments', element: }> }, { path: 'deployment', element: }> }, { path: 'jenkins', element: }> }, { path: 'external', element: ( }> ) } ] }, { path: 'system', children: [ { path: 'user', element: ( }> ) }, { path: 'role', element: ( }> ) }, { path: 'menu', element: ( }> ) }, { path: 'department', element: ( }> ) } ] }, // { // path: 'x6-test', // element: ( // }> // // // ) // }, { path: 'workflow', children: [ { path: 'definition', children: [ { path: '', element: ( }> ) }, { path: ':id/design', element: ( }> ) } ] }, { path: 'instance', element: ( }> ) }, { path: 'node-design', children: [ { index: true, element: ( }> ) }, { path: 'create', element: ( }> ) }, { path: 'design/:id', element: ( }> ) } ] }, { path: 'monitor', element: ( }> ) }, { path: 'log-stream/:processInstanceId', element: ( }> ) } ] }, { path: '*', element: } ] } ]); export default router;