fix: infinite redirect in `BACK` mode
修复后端权限模式下的路由无限重定向的问题
This commit is contained in:
parent
87583c8b54
commit
4b46a84c2b
|
|
@ -5,13 +5,40 @@ import { createFakeUserList } from './user';
|
||||||
// single
|
// single
|
||||||
const dashboardRoute = {
|
const dashboardRoute = {
|
||||||
path: '/dashboard',
|
path: '/dashboard',
|
||||||
name: 'Welcome',
|
name: 'Dashboard',
|
||||||
component: '/dashboard/analysis/index',
|
component: 'LAYOUT',
|
||||||
|
redirect: '/dashboard/analysis',
|
||||||
meta: {
|
meta: {
|
||||||
title: 'routes.dashboard.analysis',
|
title: 'routes.dashboard.dashboard',
|
||||||
affix: true,
|
hideChildrenInMenu: true,
|
||||||
icon: 'bx:bx-home',
|
icon: 'bx:bx-home',
|
||||||
},
|
},
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
path: 'analysis',
|
||||||
|
name: 'Analysis',
|
||||||
|
component: '/dashboard/analysis/index',
|
||||||
|
meta: {
|
||||||
|
hideMenu: true,
|
||||||
|
hideBreadcrumb: true,
|
||||||
|
title: 'routes.dashboard.analysis',
|
||||||
|
currentActiveMenu: '/dashboard',
|
||||||
|
icon: 'bx:bx-home',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'workbench',
|
||||||
|
name: 'Workbench',
|
||||||
|
component: '/dashboard/workbench/index',
|
||||||
|
meta: {
|
||||||
|
hideMenu: true,
|
||||||
|
hideBreadcrumb: true,
|
||||||
|
title: 'routes.dashboard.workbench',
|
||||||
|
currentActiveMenu: '/dashboard',
|
||||||
|
icon: 'bx:bx-home',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
const backRoute = {
|
const backRoute = {
|
||||||
|
|
@ -223,12 +250,21 @@ export default [
|
||||||
return resultError('Invalid user token!');
|
return resultError('Invalid user token!');
|
||||||
}
|
}
|
||||||
const id = checkUser.userId;
|
const id = checkUser.userId;
|
||||||
if (!id || id === '1') {
|
let menu: Object[];
|
||||||
return resultSuccess([dashboardRoute, authRoute, levelRoute, sysRoute, linkRoute]);
|
switch (id) {
|
||||||
}
|
case '1':
|
||||||
if (id === '2') {
|
dashboardRoute.redirect = dashboardRoute.path + '/' + dashboardRoute.children[0].path;
|
||||||
return resultSuccess([dashboardRoute, authRoute, levelRoute, linkRoute]);
|
menu = [dashboardRoute, authRoute, levelRoute, sysRoute, linkRoute];
|
||||||
|
break;
|
||||||
|
case '2':
|
||||||
|
dashboardRoute.redirect = dashboardRoute.path + '/' + dashboardRoute.children[1].path;
|
||||||
|
menu = [dashboardRoute, authRoute, levelRoute, linkRoute];
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
menu = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return resultSuccess(menu);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
] as MockMethod[];
|
] as MockMethod[];
|
||||||
|
|
|
||||||
|
|
@ -19,12 +19,6 @@ export function createPermissionGuard(router: Router) {
|
||||||
const userStore = useUserStoreWithOut();
|
const userStore = useUserStoreWithOut();
|
||||||
const permissionStore = usePermissionStoreWithOut();
|
const permissionStore = usePermissionStoreWithOut();
|
||||||
router.beforeEach(async (to, from, next) => {
|
router.beforeEach(async (to, from, next) => {
|
||||||
// Jump to the 404 page after processing the login
|
|
||||||
if (from.path === LOGIN_PATH && to.name === PAGE_NOT_FOUND_ROUTE.name) {
|
|
||||||
next(userStore.getUserInfo.homePath || PageEnum.BASE_HOME);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
from.path === ROOT_PATH &&
|
from.path === ROOT_PATH &&
|
||||||
to.path === PageEnum.BASE_HOME &&
|
to.path === PageEnum.BASE_HOME &&
|
||||||
|
|
@ -66,6 +60,17 @@ export function createPermissionGuard(router: Router) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Jump to the 404 page after processing the login
|
||||||
|
if (
|
||||||
|
from.path === LOGIN_PATH &&
|
||||||
|
to.name === PAGE_NOT_FOUND_ROUTE.name &&
|
||||||
|
to.fullPath !== (userStore.getUserInfo.homePath || PageEnum.BASE_HOME)
|
||||||
|
) {
|
||||||
|
next(userStore.getUserInfo.homePath || PageEnum.BASE_HOME);
|
||||||
|
console.log({ from, to });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (permissionStore.getIsDynamicAddedRoute) {
|
if (permissionStore.getIsDynamicAddedRoute) {
|
||||||
next();
|
next();
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue