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 WorkflowDefinitionList = lazy(() => import('../pages/Workflow/Definition'));
const WorkflowDesign = lazy(() => import('../pages/Workflow/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 JenkinsManagerList = lazy(() => import('../pages/Deploy/JenkinsManager/List'));
const GitManagerList = lazy(() => import('../pages/Deploy/GitManager/List'));
const External = lazy(() => import('../pages/Deploy/External'));
const FormDesigner = lazy(() => import('../pages/FormDesigner'));
// Workflow2 相关路由已迁移到 Workflow,删除旧路由
// 创建路由
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-manager',
element: }>
},
{
path: 'git-manager',
element: }>
},
{
path: 'external',
element: (
}>
)
}
]
},
{
path: 'system',
children: [
{
path: 'user',
element: (
}>
)
},
{
path: 'role',
element: (
}>
)
},
{
path: 'menu',
element: (
}>
)
},
{
path: 'department',
element: (
}>
)
}
]
},
{
path: 'workflow',
children: [
{
path: 'definition',
element: (
}>
)
},
{
path: 'design',
children: [
{
path: ':id',
element: (
}>
)
}
]
},
{
path: 'instance',
element: (
}>
)
},
{
path: 'node-design',
children: [
{
index: true,
element: (
}>
)
},
{
path: 'create',
element: (
}>
)
},
{
path: 'design/:id',
element: (
}>
)
}
]
},
{
path: 'monitor',
element: (
}>
)
},
{
path: 'form-designer',
element: (
}>
)
},
{
path: 'log-stream/:processInstanceId',
element: (
}>
)
}
]
},
{
path: '*',
element:
}
]
}
]);
export default router;