修复路由守卫next多次调用的问题

This commit is contained in:
2024-09-01 15:47:33 +08:00
parent 0d33e18a88
commit 1709552ed4

View File

@@ -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()
}) })