111
jihongshun
8 天以前 0c741cdda7ef9935a20d3090dfea97e1ce8ae754
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
import router from './router'
import { getToken } from '@/utils/auth'
import env from "/env"; // get token from cookie
 
const whiteList = ['/login', '/404', '/design','/design/poi', '/view', '/preview'] // no redirect whitelist
 
router.beforeEach(async(to, from, next) => {
  const hasToken = getToken()
  if (hasToken) {
    if (to.path === '/login') {
      next({ path: '/' })
    } else {
      next()
    }
  } else {
    if (whiteList.indexOf(to.path) !== -1) {
      if ('/design' === to.path && env.active === 'dev'){
        next(`/login`)
      }
      next()
    } else {
      next(`/login?redirect=${to.path}`)
    }
  }
})
 
router.afterEach(() => {
})