fix: next to login when token is not right

This commit is contained in:
Pan 2017-10-25 17:37:42 +08:00
parent 9788cdab23
commit 576e37762a
1 changed files with 6 additions and 0 deletions

View File

@ -2,6 +2,7 @@ import router from './router'
import store from './store'
import NProgress from 'nprogress' // Progress 进度条
import 'nprogress/nprogress.css'// Progress 进度条样式
import { Message } from 'element-ui'
import { getToken } from '@/utils/auth' // 验权
const whiteList = ['/login'] // 不重定向白名单
@ -14,6 +15,11 @@ router.beforeEach((to, from, next) => {
if (store.getters.roles.length === 0) {
store.dispatch('GetInfo').then(res => { // 拉取用户信息
next()
}).catch(() => {
store.dispatch('FedLogOut').then(() => {
Message.error('验证失败,请重新登录')
next({ path: '/login' })
})
})
} else {
next()