router.beforeEach((to, from, next) => {
//配置路由守卫
if(to.path==='/'||store.state.user.id){
next()
}else{
next({
path: '/',query: {
redirect: to.path}});
}
});
next({ path: "/?redirect=" + to.path});
这种写法出错的情况:当你的身份信息失效,请求一个/employee路径,会到else,然后执行next({ path: “/login?redirect=” + to.path});因为指定path为"/login?redirect=" + to.path的同时没有指定query,router组件不会再解析query参数,也就得不到重定向效果,登陆成功就去了首页而不是/employee页面。
然后定义路由,写el-menu

最低0.47元/天 解锁文章
8403

被折叠的 条评论
为什么被折叠?



