xinggevip

Vue2.x Cli3.x 导航守卫(全局守卫)
//全局守卫 router.beforeEach((to,from,next) =>{ // alert...
扫描右侧二维码阅读全文
27
2019/05

Vue2.x Cli3.x 导航守卫(全局守卫)

//全局守卫
router.beforeEach((to,from,next) =>{
  // alert("还没有登陆,请登录");
  // next();
  // console.log(to);
  // 判断store.gettes.isLogin === false
  // 实现的效果:判断是否为登陆状态,如果不是则提示登陆并跳转到登陆页面,只能点击登陆和注册路由链接
  if(to.path == '/login' || to.path =='/register'){
    next();
  }else{
    alert("还没有登陆,请先登陆!");
    next('/login');
  }
})
Last modification:May 27th, 2019 at 10:08 pm
If you think my article is useful to you, please feel free to appreciate

Leave a Comment