最终效果是 如果没有登录,无论你访问哪个页面都会拦截并提示重新登录 router.beforeEach((to,from,next)=>{ if(to.path=='/logins'|| localStorage.getItem('userid')){ next(); }else{ alert('请重新登录'); next('/logins'); } })