vue路由守卫

先在路由中设置
meta:{requireAuth:true},
然后在main。js中
router.beforeEach((to, from, next) => {
 
//to指代的是当前循环出来的路由对象
if(to.meta.requireAuth){

//根据token来决定是否能看到管理系统
token(localStorage.getItem('tokenid')).then((res) => {
if(res.data == 'ok'){
//用户已登录
next() //放行
}else next('/') //跳转到登录页面!
})

}else{
//没有开启路由验证
next() //放行 让他跳转
}

})

 

posted @ 2019-07-20 16:06  无人像你minister  阅读(691)  评论(0)    收藏  举报