Vue 路由导航守卫
程序员文章站
2022-03-24 18:38:45
...
Vue 路由导航守卫
router.beforeEach((to, from, next) => {
let userInfo = localStorage.getItem('userInfo');
let leftList = JSON.parse(window.localStorage.getItem("Menu"))
if (userInfo && to.path == '/login') {
next({
path: '/',
replace: true
})
} else if (!userInfo && to.path != '/login' ) {
next({
path: '/login',
replace: true
})
} else {
next()
}
})```