Commit 4b46a84c2b85e8da799426c54b3381ae93183db4

Authored by 无木
1 parent 87583c8b

fix: infinite redirect in `BACK` mode

修复后端权限模式下的路由无限重定向的问题
mock/sys/menu.ts
... ... @@ -5,13 +5,40 @@ import { createFakeUserList } from './user';
5 5 // single
6 6 const dashboardRoute = {
7 7 path: '/dashboard',
8   - name: 'Welcome',
9   - component: '/dashboard/analysis/index',
  8 + name: 'Dashboard',
  9 + component: 'LAYOUT',
  10 + redirect: '/dashboard/analysis',
10 11 meta: {
11   - title: 'routes.dashboard.analysis',
12   - affix: true,
  12 + title: 'routes.dashboard.dashboard',
  13 + hideChildrenInMenu: true,
13 14 icon: 'bx:bx-home',
14 15 },
  16 + children: [
  17 + {
  18 + path: 'analysis',
  19 + name: 'Analysis',
  20 + component: '/dashboard/analysis/index',
  21 + meta: {
  22 + hideMenu: true,
  23 + hideBreadcrumb: true,
  24 + title: 'routes.dashboard.analysis',
  25 + currentActiveMenu: '/dashboard',
  26 + icon: 'bx:bx-home',
  27 + },
  28 + },
  29 + {
  30 + path: 'workbench',
  31 + name: 'Workbench',
  32 + component: '/dashboard/workbench/index',
  33 + meta: {
  34 + hideMenu: true,
  35 + hideBreadcrumb: true,
  36 + title: 'routes.dashboard.workbench',
  37 + currentActiveMenu: '/dashboard',
  38 + icon: 'bx:bx-home',
  39 + },
  40 + },
  41 + ],
15 42 };
16 43  
17 44 const backRoute = {
... ... @@ -223,12 +250,21 @@ export default [
223 250 return resultError('Invalid user token!');
224 251 }
225 252 const id = checkUser.userId;
226   - if (!id || id === '1') {
227   - return resultSuccess([dashboardRoute, authRoute, levelRoute, sysRoute, linkRoute]);
228   - }
229   - if (id === '2') {
230   - return resultSuccess([dashboardRoute, authRoute, levelRoute, linkRoute]);
  253 + let menu: Object[];
  254 + switch (id) {
  255 + case '1':
  256 + dashboardRoute.redirect = dashboardRoute.path + '/' + dashboardRoute.children[0].path;
  257 + menu = [dashboardRoute, authRoute, levelRoute, sysRoute, linkRoute];
  258 + break;
  259 + case '2':
  260 + dashboardRoute.redirect = dashboardRoute.path + '/' + dashboardRoute.children[1].path;
  261 + menu = [dashboardRoute, authRoute, levelRoute, linkRoute];
  262 + break;
  263 + default:
  264 + menu = [];
231 265 }
  266 +
  267 + return resultSuccess(menu);
232 268 },
233 269 },
234 270 ] as MockMethod[];
... ...
src/router/guard/permissionGuard.ts
... ... @@ -19,12 +19,6 @@ export function createPermissionGuard(router: Router) {
19 19 const userStore = useUserStoreWithOut();
20 20 const permissionStore = usePermissionStoreWithOut();
21 21 router.beforeEach(async (to, from, next) => {
22   - // Jump to the 404 page after processing the login
23   - if (from.path === LOGIN_PATH && to.name === PAGE_NOT_FOUND_ROUTE.name) {
24   - next(userStore.getUserInfo.homePath || PageEnum.BASE_HOME);
25   - return;
26   - }
27   -
28 22 if (
29 23 from.path === ROOT_PATH &&
30 24 to.path === PageEnum.BASE_HOME &&
... ... @@ -66,6 +60,17 @@ export function createPermissionGuard(router: Router) {
66 60 return;
67 61 }
68 62  
  63 + // Jump to the 404 page after processing the login
  64 + if (
  65 + from.path === LOGIN_PATH &&
  66 + to.name === PAGE_NOT_FOUND_ROUTE.name &&
  67 + to.fullPath !== (userStore.getUserInfo.homePath || PageEnum.BASE_HOME)
  68 + ) {
  69 + next(userStore.getUserInfo.homePath || PageEnum.BASE_HOME);
  70 + console.log({ from, to });
  71 + return;
  72 + }
  73 +
69 74 if (permissionStore.getIsDynamicAddedRoute) {
70 75 next();
71 76 return;
... ...