style(projects): 路由相关文件夹简化

This commit is contained in:
Soybean 2022-01-06 11:37:06 +08:00
parent 85b55bb37a
commit e5793e1c8d
3 changed files with 69 additions and 78 deletions

View File

@ -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 })
});

View File

@ -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;

View File

@ -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<AuthRoute.RouteKey, 'not-found-page'>): A
const path = key.split(splitMark).join(pathSplitMark);
return (pathSplitMark + path) as AuthRoute.RoutePath;
}
export { constantRoutes };