| 123456789101112131415161718192021 |
- import router from './router'
- import { getAccessToken, removeAll } from '@/utils/auth'
- router.beforeEach((to, from, next) => {
- const needAuth = to.meta.needAuth
- const token = getAccessToken()
- if (token != null) {
- if (to.path === '/login' || to.path === '/register') {
- next({ path: '/' })
- } else {
- next()
- }
- } else {
- removeAll()
- if (needAuth) {
- next('/login')
- } else {
- next()
- }
- }
- })
|