/* eslint-disable react-refresh/only-export-components -- 路由配置模块,lazy 组件仅作为路由元素,不做热更新边界 */
import { Permission } from '@lingxi/shared';
import { PageSkeleton } from '@lingxi/ui';
import { lazy, type ReactNode, Suspense } from 'react';
import { createBrowserRouter, Navigate } from 'react-router';
import { RequireAuth } from '@/components/auth/RequireAuth';
import { RequirePermission } from '@/components/auth/RequirePermission';
import { AppLayout } from '@/layout/AppLayout';
import { LegacySystemRedirect, LegacyUsersRedirect } from '@/navigation/legacy-redirect';
import { ForbiddenPage } from '@/pages/errors/ForbiddenPage';
import { NotFoundPage } from '@/pages/errors/NotFoundPage';
import { ServerErrorPage } from '@/pages/errors/ServerErrorPage';
import { UnauthorizedPage } from '@/pages/errors/UnauthorizedPage';
import { ROUTES } from '@/routes';
const UsersPage = lazy(async () => {
const module = await import('@/pages/system/users/UsersPage');
return { default: module.UsersPage };
});
const UserNewPage = lazy(async () => {
const module = await import('@/pages/system/users/UserNewPage');
return { default: module.UserNewPage };
});
const DepartmentsPage = lazy(async () => {
const module = await import('@/pages/system/departments/DepartmentsPage');
return { default: module.DepartmentsPage };
});
const RolesPage = lazy(async () => {
const module = await import('@/pages/system/roles/RolesPage');
return { default: module.RolesPage };
});
const RoleEditorPage = lazy(async () => {
const module = await import('@/pages/system/roles/RoleEditorPage');
return { default: module.RoleEditorPage };
});
const RoleNewPage = lazy(async () => {
const module = await import('@/pages/system/roles/RoleNewPage');
return { default: module.RoleNewPage };
});
const IndustriesPage = lazy(async () => {
const module = await import('@/pages/system/industries/IndustriesPage');
return { default: module.IndustriesPage };
});
const CustomersPage = lazy(async () => {
const module = await import('@/pages/system/customers/CustomersPage');
return { default: module.CustomersPage };
});
const CustomerNewPage = lazy(async () => {
const module = await import('@/pages/system/customers/CustomerNewPage');
return { default: module.CustomerNewPage };
});
const CustomerDetailPage = lazy(async () => {
const module = await import('@/pages/system/customers/CustomerDetailPage');
return { default: module.CustomerDetailPage };
});
const CustomerGroupsPage = lazy(async () => {
const module = await import('@/pages/system/customer-groups/CustomerGroupsPage');
return { default: module.CustomerGroupsPage };
});
const CustomerFieldsPage = lazy(async () => {
const module = await import('@/pages/system/customer-fields/CustomerFieldsPage');
return { default: module.CustomerFieldsPage };
});
const DictsPage = lazy(async () => {
const module = await import('@/pages/system/dicts/DictsPage');
return { default: module.DictsPage };
});
const SettingsPage = lazy(async () => {
const module = await import('@/pages/system/settings/SettingsPage');
return { default: module.SettingsPage };
});
function withSkeleton(node: ReactNode): ReactNode {
return }>{node};
}
export const router = createBrowserRouter([
// 旧地址兼容:/users* → /system/users*,/platform* → /system*
{ path: 'users', element: },
{ path: 'users/*', element: },
{ path: 'platform', element: },
{ path: 'platform/*', element: },
{
path: ROUTES.login,
lazy: async () => ({
Component: (await import('@/pages/login/LoginPage')).default,
}),
},
{
path: '/',
element: (
),
children: [
{
index: true,
lazy: async () => ({
Component: (await import('@/pages/dashboard/HomePage')).default,
}),
},
{
path: 'system',
element: ,
},
{
path: 'system/users',
element: (
{withSkeleton()}
),
},
{
path: 'system/users/new',
element: (
{withSkeleton()}
),
},
{
path: 'system/users/:id',
element: (
{withSkeleton()}
),
},
{
path: 'system/departments',
element: (
{withSkeleton()}
),
},
{
path: 'system/roles',
element: (
{withSkeleton()}
),
},
{
path: 'system/roles/new',
element: (
{withSkeleton()}
),
},
{
path: 'system/roles/:id',
element: (
{withSkeleton()}
),
},
{
path: 'system/industries',
element: (
{withSkeleton()}
),
},
{
path: 'system/customers',
element: (
{withSkeleton()}
),
},
{
path: 'system/customers/new',
element: (
{withSkeleton()}
),
},
{
path: 'system/customers/:id',
element: (
{withSkeleton()}
),
},
{
path: 'system/customer-groups',
element: (
{withSkeleton()}
),
},
{
path: 'system/customer-fields/approvals',
element: (
{withSkeleton()}
),
},
{
path: 'system/dicts',
element: (
{withSkeleton()}
),
},
{
path: 'system/dicts/:type',
element: (
{withSkeleton()}
),
},
{
path: 'system/settings',
element: (
{withSkeleton()}
),
},
{
path: ':moduleKey/:itemKey?',
lazy: async () => ({
Component: (await import('@/pages/workspace/WorkspacePage')).default,
}),
},
],
},
{ path: ROUTES.unauthorized, element: },
{ path: ROUTES.forbidden, element: },
{ path: ROUTES.notFound, element: },
{ path: ROUTES.serverError, element: },
{ path: '*', element: },
]);