@@ -13,21 +13,21 @@ const { setTitle } = useTitle()
1313
1414export function registerNavigationGuard ( router : Router ) {
1515 // 全局前置守卫
16- router . beforeEach ( async ( to , _from , next ) => {
16+ router . beforeEach ( async ( to , _from ) => {
1717 NProgress . start ( )
1818 const userStore = useUserStore ( )
1919 const permissionStore = usePermissionStore ( )
2020 // 如果没有登陆
2121 if ( ! getToken ( ) ) {
2222 // 如果在免登录的白名单中,则直接进入
23- if ( isWhiteList ( to ) ) return next ( )
23+ if ( isWhiteList ( to ) ) return true
2424 // 其他没有访问权限的页面将被重定向到登录页面
25- return next ( "/login" )
25+ return "/login"
2626 }
2727 // 如果已经登录,并准备进入 Login 页面,则重定向到主页
28- if ( to . path === "/login" ) return next ( { path : "/" } )
28+ if ( to . path === "/login" ) return "/"
2929 // 如果用户已经获得其权限角色
30- if ( userStore . roles . length !== 0 ) return next ( )
30+ if ( userStore . roles . length !== 0 ) return true
3131 // 否则要重新获取权限角色
3232 try {
3333 await userStore . getInfo ( )
@@ -38,12 +38,12 @@ export function registerNavigationGuard(router: Router) {
3838 // 将 "有访问权限的动态路由" 添加到 Router 中
3939 permissionStore . addRoutes . forEach ( route => router . addRoute ( route ) )
4040 // 设置 replace: true, 因此导航将不会留下历史记录
41- next ( { ...to , replace : true } )
41+ return { ...to , replace : true }
4242 } catch ( error ) {
4343 // 过程中发生任何错误,都直接重置 Token,并重定向到登录页面
4444 userStore . resetToken ( )
4545 ElMessage . error ( ( error as Error ) . message || "路由守卫发生错误" )
46- next ( "/login" )
46+ return "/login"
4747 }
4848 } )
4949
0 commit comments