style(projects): 路由相关文件夹简化
This commit is contained in:
parent
85b55bb37a
commit
e5793e1c8d
@ -1,11 +1,12 @@
|
|||||||
import type { App } from 'vue';
|
import type { App } from 'vue';
|
||||||
import { createRouter, createWebHistory } from 'vue-router';
|
import { createRouter, createWebHistory } from 'vue-router';
|
||||||
import { routes } from './routes';
|
import { transformAuthRoutesToVueRoutes } from '@/utils';
|
||||||
|
import { constantRoutes } from './routes';
|
||||||
import { createRouterGuide } from './guard';
|
import { createRouterGuide } from './guard';
|
||||||
|
|
||||||
export const router = createRouter({
|
export const router = createRouter({
|
||||||
history: createWebHistory(import.meta.env.BASE_URL),
|
history: createWebHistory(import.meta.env.BASE_URL),
|
||||||
routes,
|
routes: transformAuthRoutesToVueRoutes(constantRoutes),
|
||||||
scrollBehavior: () => ({ left: 0, top: 0 })
|
scrollBehavior: () => ({ left: 0, top: 0 })
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -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;
|
|
@ -1,9 +1,70 @@
|
|||||||
import type { RouteRecordRaw } from 'vue-router';
|
import { getLoginModuleRegExp } from '@/utils';
|
||||||
import { transformAuthRoutesToVueRoutes } from '@/utils';
|
import { LoginModuleKey } from '@/interface';
|
||||||
import constantRoutes from './constant';
|
|
||||||
|
|
||||||
/** 所有路由 */
|
/** 固定的路由 */
|
||||||
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;
|
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);
|
const path = key.split(splitMark).join(pathSplitMark);
|
||||||
return (pathSplitMark + path) as AuthRoute.RoutePath;
|
return (pathSplitMark + path) as AuthRoute.RoutePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
export { constantRoutes };
|
|
||||||
|
Loading…
Reference in New Issue
Block a user