路由守衛判斷有沒有token跳轉登陸

router.beforeEach((to, from, next) => {

let isLogin = window.sessionStorage.getItem('loginUserNameKey');
if (isLogin) {
//若是用戶信息存在則往下執行。
next()
} else {
//若是用戶token不存在則跳轉到login頁面
if (to.path === '/login') {
next()
} else {
next('/login')
}
}
})
相關文章
相關標籤/搜索