quanwei
18 hours ago c441dea81bd86bdfb12dff35821fed51f4cc91c2
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
import router, {
  resetRouter
} from './router'
import store from './store/'
import {
  Message,
  Loading
} from 'element-ui'
import NProgress from 'nprogress' // progress bar
import 'nprogress/nprogress.css' // progress bar style
import {
  getCookie,
  setCookie
} from '@/utils/base'
 
 const whiteList = ['/login', '/test', '/fonticon']
// åœ¨æ¯ä¸ªè·¯ç”±ç”Ÿæ•ˆä¹‹å‰ï¼Œå…ˆè¿›è¡Œä¸€äº›å¤„理,请参è€?vue-router官方文档-导航钩子
router.beforeEach((to, from, next) => {
 
  const isLogin = getCookie('isLogin');
  
  if(isLogin){
    NProgress.start();
    next();
    NProgress.done();
  }else{
    if(whiteList.indexOf(to.path.toLowerCase()) !== -1) {
      next();
    }else{
       next('/Login');
    }
  }
 
})