前端登录功能补充

This commit is contained in:
2024-08-31 22:53:02 +08:00
parent c961cb0508
commit e0c9b5d67c

View File

@@ -39,9 +39,25 @@ const router = createRouter({
name: 'login', name: 'login',
component: () => import('../views/Console/Login.vue') component: () => import('../views/Console/Login.vue')
}, },
{
path: 'dashboard',
name: 'dashboard',
component: () => import('../views/Console/Dashboard.vue')
}
], ],
} }
] ]
}) })
router.beforeEach((to, from, next) => {
const isAuthenticated = !!localStorage.getItem('jwtToken');
if (to.name === 'dashboard' && !isAuthenticated) {
next({ name: 'login' });
} else if (to.name === 'login' && isAuthenticated) {
next({ name: 'dashboard' });
}
next()
})
export default router export default router