You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

38 lines
983 B

import router from './router'
import store from './store'
import NProgress from 'nprogress' // Progress 进度条
import 'nprogress/nprogress.css'// Progress 进度条样式
import { getToken } from '@/utils/auth' // 验权
const whiteList = ['/login', '/remote', '/404', '/fangwei'] // 不重定向白名单
router.beforeEach((to, from, next) => {
NProgress.start()
if (getToken()) {
if (to.path === '/login') {
next({ path: '/' })
NProgress.done() // 结束Progress
} else if (store.getters.roles.length) {
next()
} else {
store.dispatch('GetInfo').then(() => {
next({ ...to, replace: true })
})
}
} else {
const ppath = to.path
let flag = true
whiteList.find(function(value) {
if (ppath.indexOf(value) !== -1) {
flag = false
next()
}
})
if (flag) {
next('/login')
NProgress.done()
}
}
})
router.afterEach(() => {
NProgress.done() // 结束Progress
})