router.beforeEach((to, from, next) => {
  const tokenStr = window.sessionStorage.getItem('Tk_token');
  if(!tokenStr){
    if(to.path==='/user'|| to.path==='/cartShop'){
      next('/login');
    }else{
      window.scroll(0, 0);  //  <= 这个
      next();
    }  
  }else{
    window.scroll(0, 0);
    next();
  }

});

Logo

前往低代码交流专区

更多推荐