feat: route/index 重构
This commit is contained in:
5
src/routes/constants/index.js
Normal file
5
src/routes/constants/index.js
Normal file
@@ -0,0 +1,5 @@
|
||||
// src/routes/constants/index.js
|
||||
// 统一导出所有路由常量
|
||||
|
||||
export { LAYOUT_COMPONENTS } from './layoutComponents';
|
||||
export { PROTECTION_WRAPPER_MAP } from './protectionWrappers';
|
||||
26
src/routes/constants/layoutComponents.js
Normal file
26
src/routes/constants/layoutComponents.js
Normal file
@@ -0,0 +1,26 @@
|
||||
// src/routes/constants/layoutComponents.js
|
||||
// 布局组件映射表
|
||||
|
||||
import Auth from '@layouts/Auth';
|
||||
import HomeLayout from '@layouts/Home';
|
||||
|
||||
/**
|
||||
* 特殊布局组件映射表
|
||||
*
|
||||
* 用于将字符串标识符映射到实际的组件。
|
||||
* 这些是非懒加载的布局组件,在 routeConfig.js 中通过字符串引用。
|
||||
*
|
||||
* @example
|
||||
* // 在 routeConfig.js 中:
|
||||
* {
|
||||
* path: 'auth/*',
|
||||
* component: 'Auth', // 字符串标识符
|
||||
* ...
|
||||
* }
|
||||
*
|
||||
* // 通过 LAYOUT_COMPONENTS['Auth'] 获取实际组件
|
||||
*/
|
||||
export const LAYOUT_COMPONENTS = {
|
||||
Auth,
|
||||
HomeLayout,
|
||||
};
|
||||
24
src/routes/constants/protectionWrappers.js
Normal file
24
src/routes/constants/protectionWrappers.js
Normal file
@@ -0,0 +1,24 @@
|
||||
// src/routes/constants/protectionWrappers.js
|
||||
// 路由保护包装器映射表
|
||||
|
||||
import ProtectedRoute from '@components/ProtectedRoute';
|
||||
import ProtectedRouteRedirect from '@components/ProtectedRouteRedirect';
|
||||
import { PROTECTION_MODES } from '../routeConfig';
|
||||
|
||||
/**
|
||||
* 保护模式包装器映射表
|
||||
*
|
||||
* 根据路由的保护模式选择对应的保护组件。
|
||||
* 支持以下保护模式:
|
||||
* - MODAL: 弹窗登录模式 (ProtectedRoute)
|
||||
* - REDIRECT: 跳转登录模式 (ProtectedRouteRedirect)
|
||||
* - PUBLIC: 公开访问,无保护 (无包装器)
|
||||
*
|
||||
* @example
|
||||
* const WrapperComponent = PROTECTION_WRAPPER_MAP[PROTECTION_MODES.MODAL];
|
||||
* // 返回 ProtectedRoute 组件
|
||||
*/
|
||||
export const PROTECTION_WRAPPER_MAP = {
|
||||
[PROTECTION_MODES.MODAL]: ProtectedRoute,
|
||||
[PROTECTION_MODES.REDIRECT]: ProtectedRouteRedirect,
|
||||
};
|
||||
Reference in New Issue
Block a user