zhongrj
2026-06-02 0299e41c6692684d943b4a206472a86ea84ea4b5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import router from "@/router/page/index";
import store from './store'
import { getToken } from "./utils/auth";
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
 
NProgress.configure({showSpinner: false});
 
router.beforeEach((to, from, next) => {
  const meta = to.meta || {};
 
  if (getToken()) {
    if (to.path === '/login') {
      next({ path: '/layout/home' })
    } else {
      if (store.getters.token.length === 0) {
        store.dispatch('FedLogOut').then(() => {
          next({ path: '/login' })
        })
      } else {
        next()
      }
    }
  } else {
    if (meta.isAuth === false) {
      next()
    } else {
      next('/login')
    }
  }
});
 
router.afterEach(() => {
  NProgress.done();
});