router.beforeEach((to, from, next) => {
next()//没有用处,继续访问
})
to 访问到哪
from 从哪访问
next 继续访问
router.beforeEach((to, from, next) => {
if (to.path !== "/login") {
//如果不是从登录页来的,判断本地存储是否已经有了用户名
if (localStorage.getItem("usr")) {
//若已经有了usr,继续
next()
} else {
//没有的话跳转回/login
next("/login")
}
} else {
//继续
next()
}
})