mirror of
https://github.com/m-xlsea/ruoyi-plus-soybean.git
synced 2025-09-24 07:49:47 +08:00
refactor(projects): 精简版+动态路由权限初步
This commit is contained in:
@ -1,85 +0,0 @@
|
||||
import type { RouteRecordRaw } from 'vue-router';
|
||||
import { BlankLayout } from '@/layouts';
|
||||
import type { LoginModuleType } from '@/interface';
|
||||
import { Login, NoPermission, NotFound, ServiceError } from '@/views';
|
||||
import { getLoginModuleRegExp } from '@/utils';
|
||||
import { routeName, routePath, routeTitle } from '../constant';
|
||||
import { ROUTE_HOME_NAME } from './route-home';
|
||||
|
||||
/**
|
||||
* 固定不变的路由
|
||||
* @description !最后一项重定向未找到的路由须放置路由的最后一项
|
||||
*/
|
||||
const constantRoutes: RouteRecordRaw[] = [
|
||||
{
|
||||
name: routeName('root'),
|
||||
path: routePath('root'),
|
||||
redirect: { name: ROUTE_HOME_NAME }
|
||||
},
|
||||
{
|
||||
// 名称、路径随意,不在路由声明里面,只是为各个子路由充当应用BlankLayout布局的桥梁,因此访问该路由时重定向到404
|
||||
name: 'constant-single_',
|
||||
path: '/constant-single_',
|
||||
component: BlankLayout,
|
||||
redirect: { name: routeName('not-found') },
|
||||
meta: {
|
||||
title: 'constant-single_',
|
||||
keepAlive: true
|
||||
},
|
||||
children: [
|
||||
// 登录
|
||||
{
|
||||
name: routeName('login'),
|
||||
path: `${routePath('login')}/:module(${getLoginModuleRegExp()})?`,
|
||||
component: Login,
|
||||
props: route => {
|
||||
const moduleType = (route.params.module as LoginModuleType) || 'pwd-login';
|
||||
return {
|
||||
module: moduleType
|
||||
};
|
||||
},
|
||||
meta: {
|
||||
title: routeTitle('login'),
|
||||
fullPage: true
|
||||
}
|
||||
},
|
||||
// 403
|
||||
{
|
||||
name: routeName('no-permission'),
|
||||
path: routePath('no-permission'),
|
||||
component: NoPermission,
|
||||
meta: {
|
||||
title: routeTitle('no-permission'),
|
||||
fullPage: true
|
||||
}
|
||||
},
|
||||
// 404
|
||||
{
|
||||
name: routeName('not-found'),
|
||||
path: routePath('not-found'),
|
||||
component: NotFound,
|
||||
meta: {
|
||||
title: routeTitle('not-found'),
|
||||
fullPage: true
|
||||
}
|
||||
},
|
||||
// 500
|
||||
{
|
||||
name: routeName('service-error'),
|
||||
path: routePath('service-error'),
|
||||
component: ServiceError,
|
||||
meta: {
|
||||
title: routeTitle('service-error'),
|
||||
fullPage: true
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
// 匹配无效的路径重定向404
|
||||
{
|
||||
path: '/:pathMatch(.*)*',
|
||||
redirect: { name: routeName('not-found') }
|
||||
}
|
||||
];
|
||||
|
||||
export default constantRoutes;
|
59
src/router/routes/constant.ts
Normal file
59
src/router/routes/constant.ts
Normal file
@ -0,0 +1,59 @@
|
||||
/** 固定的路由 */
|
||||
const constantRoutes: AuthRoute.Route[] = [
|
||||
{
|
||||
name: 'root',
|
||||
path: '/',
|
||||
redirect: '/dashboard/analysis',
|
||||
meta: {
|
||||
title: 'Root'
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'login',
|
||||
path: '/login',
|
||||
component: 'blank',
|
||||
meta: {
|
||||
title: '登录',
|
||||
single: true
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'no-permission',
|
||||
path: '/no-permission',
|
||||
component: 'blank',
|
||||
meta: {
|
||||
title: '无权限',
|
||||
single: true
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'not-found',
|
||||
path: '/not-found',
|
||||
component: 'blank',
|
||||
meta: {
|
||||
title: '未找到',
|
||||
single: true
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'service-error',
|
||||
path: '/service-error',
|
||||
component: 'blank',
|
||||
meta: {
|
||||
title: '服务器错误',
|
||||
single: true
|
||||
}
|
||||
},
|
||||
// 匹配无效的路径重定向not-found的页面
|
||||
{
|
||||
name: 'redirect-not-found',
|
||||
path: '/:pathMatch(.*)*',
|
||||
component: 'blank',
|
||||
meta: {
|
||||
title: '未找到',
|
||||
single: true
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
export default constantRoutes;
|
@ -1,11 +1,8 @@
|
||||
import type { RouteRecordRaw } from 'vue-router';
|
||||
import { transformMultiDegreeRoutes } from '@/utils';
|
||||
import customRoutes from '../modules';
|
||||
import constantRoutes from './constant-routes';
|
||||
|
||||
const transformRoutes = transformMultiDegreeRoutes(customRoutes);
|
||||
import { transformAuthRouteToVueRoute } from '@/utils';
|
||||
import constantRoutes from './constant';
|
||||
|
||||
/** 所有路由 */
|
||||
export const routes: RouteRecordRaw[] = [...transformRoutes, ...constantRoutes];
|
||||
export const routes: RouteRecordRaw[] = constantRoutes.map(item => transformAuthRouteToVueRoute(item));
|
||||
|
||||
export { ROUTE_HOME } from './route-home';
|
||||
export { constantRoutes };
|
||||
|
@ -1,9 +0,0 @@
|
||||
import { getRouteHome } from '@/utils';
|
||||
import { routeName } from '../constant';
|
||||
import customRoutes from '../modules';
|
||||
|
||||
/** 路由首页的名字 */
|
||||
export const ROUTE_HOME_NAME = routeName('dashboard_analysis');
|
||||
|
||||
/** 路由首页 */
|
||||
export const ROUTE_HOME = getRouteHome(customRoutes, ROUTE_HOME_NAME);
|
Reference in New Issue
Block a user