12345678910router.beforeEach((to, from, next) => { const token = window.sessionStorage.getItem('token') if (to.fullPath !== '/login' && !token) { console.log('no token,please login.') next('/login') } // 如果用户未能验证身份,则 `next` 会被调用两次 next()})