修复路由守卫next多次调用的问题
This commit is contained in:
@@ -52,9 +52,9 @@ const router = createRouter({
|
|||||||
router.beforeEach((to, from, next) => {
|
router.beforeEach((to, from, next) => {
|
||||||
const isAuthenticated = !!localStorage.getItem('jwtToken');
|
const isAuthenticated = !!localStorage.getItem('jwtToken');
|
||||||
if (to.name === 'dashboard' && !isAuthenticated) {
|
if (to.name === 'dashboard' && !isAuthenticated) {
|
||||||
next({ name: 'login' });
|
return next({ name: 'login' });
|
||||||
} else if (to.name === 'login' && isAuthenticated) {
|
} else if (to.name === 'login' && isAuthenticated) {
|
||||||
next({ name: 'dashboard' });
|
return next({ name: 'dashboard' });
|
||||||
}
|
}
|
||||||
next()
|
next()
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user