关于next() :是否通过
参数:
有些登录是需要验证的
1,没有登陆 跳转到登录页
2,登录 直接进入
有些路由不需要登录 直接进入
ps:是否需要登录 -- meta
代码展示:
if(to.matched.some(item => item.meta.login)){ //需要登录
console.log('需要登录一下');
if(isLogin){
if(data.error === 400){//后端会通知你,登录不成功
next({name:'home'});
localStorage.removeItem('token');
return;
}
//已经登录,直接通过
if(to.name === 'login'){
next({name:'home'});
}else{
next();
}
return;
}else if(!isLogin && to.name === 'login'){
//未登录,但是需要去登录页
next();
}else if(!isLogin && to.name !== 'login'){
//未登录,但是去的不是登录页
next({name:'login'})
}
}else{
next();
}