VUE根据token,路由判断用户登录状态并跳转登录页
router.beforeEach((to, from, next) => {var token = library.getData("userName");//如果没登录,都导向登录页if (!token) {if (to.path !== '/Login') {next({ path: '/Login' })}else {...
·
router.beforeEach((to, from, next) => {
var token = library.getData("userName");
//如果没登录,都导向登录页
if (!token) {
if (to.path !== '/Login') {
next({ path: '/Login' })
}
else {
next();
}
}
else {
next();
}
})
/**
* 跳转登陆页面强制刷新,相当于F5
*/
router.afterEach((to,from)=>{
if(from.path != '/Login' && from.path != '/' && to.path == '/Login'){
window.location.reload();
}
})
更多推荐
已为社区贡献27条内容
所有评论(0)