防止next(’/login’)进入死循环,一定要判断to.path==’/login’.前往登录页是要放行
//前置守卫
router.beforeEach((to, from, next) => {
let token = sessionStorage.getItem('TOKEN')
// log({ type: 'success', message: 'token', variable: token, row: '59', filename: 'router' });
if (token === null || token === '') {
if (to.path == '/login') {
next()
} else {
next('/login')
}
} else {
next()
}
})