diff --git a/src/router/index.ts b/src/router/index.ts index d33f55af..67a9a963 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -1,11 +1,12 @@ import type { App } from 'vue'; import { createRouter, createWebHistory } from 'vue-router'; -import { routes } from './routes'; +import { transformAuthRoutesToVueRoutes } from '@/utils'; +import { constantRoutes } from './routes'; import { createRouterGuide } from './guard'; export const router = createRouter({ history: createWebHistory(import.meta.env.BASE_URL), - routes, + routes: transformAuthRoutesToVueRoutes(constantRoutes), scrollBehavior: () => ({ left: 0, top: 0 }) }); diff --git a/src/router/routes/constant.ts b/src/router/routes/constant.ts deleted file mode 100644 index c49933f9..00000000 --- a/src/router/routes/constant.ts +++ /dev/null @@ -1,69 +0,0 @@ -import { getLoginModuleRegExp } from '@/utils'; -import { LoginModuleKey } from '@/interface'; - -/** 固定的路由 */ -const constantRoutes: AuthRoute.Route[] = [ - { - name: 'root', - path: '/', - redirect: '/dashboard/analysis', - meta: { - title: 'Root' - } - }, - { - name: 'login', - path: '/login', - component: 'self', - props: route => { - const moduleType = (route.params.module as LoginModuleKey) || 'pwd-login'; - return { - module: moduleType - }; - }, - meta: { - title: '登录', - dynamicPath: `/login/:module(${getLoginModuleRegExp()})?`, - singleLayout: 'blank' - } - }, - { - name: 'no-permission', - path: '/no-permission', - component: 'self', - meta: { - title: '无权限', - singleLayout: 'blank' - } - }, - { - name: 'not-found', - path: '/not-found', - component: 'self', - meta: { - title: '未找到', - singleLayout: 'blank' - } - }, - { - name: 'service-error', - path: '/service-error', - component: 'self', - meta: { - title: '服务器错误', - singleLayout: 'blank' - } - }, - // 匹配无效的路径重定向not-found的页面 - { - name: 'not-found-page', - path: '/:pathMatch(.*)*', - component: 'blank', - meta: { - title: '未找到', - singleLayout: 'blank' - } - } -]; - -export default constantRoutes; diff --git a/src/router/routes/index.ts b/src/router/routes/index.ts index c4419486..6546565d 100644 --- a/src/router/routes/index.ts +++ b/src/router/routes/index.ts @@ -1,9 +1,70 @@ -import type { RouteRecordRaw } from 'vue-router'; -import { transformAuthRoutesToVueRoutes } from '@/utils'; -import constantRoutes from './constant'; +import { getLoginModuleRegExp } from '@/utils'; +import { LoginModuleKey } from '@/interface'; -/** 所有路由 */ -export const routes: RouteRecordRaw[] = transformAuthRoutesToVueRoutes(constantRoutes); +/** 固定的路由 */ +export const constantRoutes: AuthRoute.Route[] = [ + { + name: 'root', + path: '/', + redirect: '/dashboard/analysis', + meta: { + title: 'Root' + } + }, + { + name: 'login', + path: '/login', + component: 'self', + props: route => { + const moduleType = (route.params.module as LoginModuleKey) || 'pwd-login'; + return { + module: moduleType + }; + }, + meta: { + title: '登录', + dynamicPath: `/login/:module(${getLoginModuleRegExp()})?`, + singleLayout: 'blank' + } + }, + { + name: 'no-permission', + path: '/no-permission', + component: 'self', + meta: { + title: '无权限', + singleLayout: 'blank' + } + }, + { + name: 'not-found', + path: '/not-found', + component: 'self', + meta: { + title: '未找到', + singleLayout: 'blank' + } + }, + { + name: 'service-error', + path: '/service-error', + component: 'self', + meta: { + title: '服务器错误', + singleLayout: 'blank' + } + }, + // 匹配无效的路径重定向not-found的页面 + { + name: 'not-found-page', + path: '/:pathMatch(.*)*', + component: 'blank', + meta: { + title: '未找到', + singleLayout: 'blank' + } + } +]; /** 路由名称 */ export const routeName = (key: AuthRoute.RouteKey) => key; @@ -17,5 +78,3 @@ export function routePath(key: Exclude): A const path = key.split(splitMark).join(pathSplitMark); return (pathSplitMark + path) as AuthRoute.RoutePath; } - -export { constantRoutes };