//出现问题时使用
const originalPush=VueRouter.prototype.push
VueRouter.prototype.push=function push(location,onResolve,onReject){
if(onResolve||onReject)return originalPush.call(this,location,onResolve,onReject)
return originalPush.call(this,location).catch(err=>err)
}
//挂载路由导航守卫
router.beforeEach((to,from,next)=>{
//to将要访问
//from从哪访问
//next接着干 next(url)重定向到url上 next()继续访问to路径
if(to.path=='/login')return next();
//获取user
const userFlog=window.sessionStorage.getItem("user");//取出当前用户
if(!userFlog)return next('/login');//无值,返回登录页
next();//符合要求,放行
})
router中的index.js挂载路由导航守卫
最新推荐文章于 2024-04-16 14:30:17 发布