router.beforeEach((to, from, next) => {
  var token = library.getData("userName");
  //如果没登录,都导向登录页
  if (!token) {
    if (to.path !== '/Login') {
      next({ path: '/Login' })
    }
    else {
      next();
    }
  }
  else {
    next();
  }
})
/**
 * 跳转登陆页面强制刷新,相当于F5
 */
router.afterEach((to,from)=>{
  if(from.path != '/Login' && from.path != '/' && to.path == '/Login'){
      window.location.reload();
  }
})

 

Logo

前往低代码交流专区

更多推荐