router.beforeEach((to, from, next) => { if (to.matched.length === 0) { next('/error404') } else { if (!sessionStorage.getItem('sid')&&to.path!="/login") { next('/login') } else { next() } } });
一定要验证页面是不是login页面,否则会陷入进入login页面的死循环