vue 全局路由守卫,系统未登录时自动跳转到登录页面
main.js:
router.beforeEach((to, from, next) => { const loginPath = '/login' if (to.path !== loginPath && !localStorage.getItem('user')) { next(loginPath) } else { next() } })
main.js:
router.beforeEach((to, from, next) => { const loginPath = '/login' if (to.path !== loginPath && !localStorage.getItem('user')) { next(loginPath) } else { next() } })