@@ -8,6 +8,7 @@ import { useUserStoreWithOut } from '/@/store/modules/user';
88import { PAGE_NOT_FOUND_ROUTE } from '/@/router/routes/basic' ;
99
1010import { RootRoute } from '/@/router/routes' ;
11+ import { omit } from 'lodash-es' ;
1112
1213const LOGIN_PATH = PageEnum . BASE_LOGIN ;
1314
@@ -18,26 +19,20 @@ const whitePathList: PageEnum[] = [LOGIN_PATH];
1819export function createPermissionGuard ( router : Router ) {
1920 const userStore = useUserStoreWithOut ( ) ;
2021 const permissionStore = usePermissionStoreWithOut ( ) ;
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-
22+ router . beforeEach ( async ( to , from ) => {
2823 if (
2924 from . path === ROOT_PATH &&
3025 to . path === PageEnum . BASE_HOME &&
3126 userStore . getUserInfo . homePath &&
3227 userStore . getUserInfo . homePath !== PageEnum . BASE_HOME
3328 ) {
34- next ( userStore . getUserInfo . homePath ) ;
35- return ;
29+ // next(userStore.getUserInfo.homePath);
30+ return userStore . getUserInfo . homePath ;
3631 }
3732
3833 // Whitelist can be directly entered
3934 if ( whitePathList . includes ( to . path as PageEnum ) ) {
40- next ( ) ;
35+ // next();
4136 return ;
4237 }
4338
@@ -47,7 +42,7 @@ export function createPermissionGuard(router: Router) {
4742 if ( ! token ) {
4843 // You can access without permission. You need to set the routing meta.ignoreAuth to true
4944 if ( to . meta . ignoreAuth ) {
50- next ( ) ;
45+ // next();
5146 return ;
5247 }
5348
@@ -62,12 +57,18 @@ export function createPermissionGuard(router: Router) {
6257 redirect : to . path ,
6358 } ;
6459 }
65- next ( redirectData ) ;
66- return ;
60+ //next(redirectData);
61+ return redirectData ;
62+ }
63+
64+ // Jump to the 404 page after processing the login
65+ if ( from . path === LOGIN_PATH && to . name === PAGE_NOT_FOUND_ROUTE . name ) {
66+ //next(userStore.getUserInfo.homePath || PageEnum.BASE_HOME);
67+ return userStore . getUserInfo . homePath || PageEnum . BASE_HOME ;
6768 }
6869
6970 if ( permissionStore . getIsDynamicAddedRoute ) {
70- next ( ) ;
71+ // next();
7172 return ;
7273 }
7374
@@ -79,8 +80,12 @@ export function createPermissionGuard(router: Router) {
7980
8081 const redirectPath = ( from . query . redirect || to . path ) as string ;
8182 const redirect = decodeURIComponent ( redirectPath ) ;
82- const nextData = to . path === redirect ? { ...to , replace : true } : { path : redirect } ;
83+ const nextData =
84+ to . path === redirect
85+ ? { ...omit ( to , [ 'name' , 'params' ] ) , replace : true }
86+ : { path : redirect } ;
8387 permissionStore . setDynamicAddedRoute ( true ) ;
84- next ( nextData ) ;
88+ // next(nextData);
89+ return nextData ;
8590 } ) ;
8691}
0 commit comments