在优化vue 的路由时,设置路由拦截,陷入死循环,尝试了很多方法
话不多说,上代码:
1、设置去到指定页面时,要把path修改成指定页面
router.beforeEach((to, from, next) => {
if(store.state.logined){
next();
}else {
//没有登录,去跳转登录页
if(to.path === '/login'){
next();
}else {
next({
path:'/login'
});
}
}
});