|
|
@@ -1,12 +1,12 @@
|
|
|
import router from './router'
|
|
|
import store from './store'
|
|
|
-import { Message } from 'element-ui'
|
|
|
+import {Message} from 'element-ui'
|
|
|
import NProgress from 'nprogress' // progress bar
|
|
|
import 'nprogress/nprogress.css' // progress bar style
|
|
|
-import { getToken } from '@/utils/auth' // get token from cookie
|
|
|
+import {getToken} from '@/utils/auth' // get token from cookie
|
|
|
import getPageTitle from '@/utils/get-page-title'
|
|
|
|
|
|
-NProgress.configure({ showSpinner: false }) // NProgress Configuration
|
|
|
+NProgress.configure({showSpinner: false}) // NProgress Configuration
|
|
|
|
|
|
const whiteList = ['/login', '/auth-redirect', '/login1'] // no redirect whitelist
|
|
|
|
|
|
@@ -23,7 +23,12 @@ router.beforeEach(async(to, from, next) => {
|
|
|
if (hasToken) {
|
|
|
if (to.path === '/login') {
|
|
|
// if is logged in, redirect to the home page
|
|
|
- next({ path: '/' })
|
|
|
+ next({path: '/dashboard-screen'})
|
|
|
+ NProgress.done() // hack: https://github.com/PanJiaChen/vue-element-admin/pull/2939
|
|
|
+ }
|
|
|
+ if (to.path === '/index') {
|
|
|
+ // if is logged in, redirect to the home page
|
|
|
+ next({path: '/dashboard-screen'})
|
|
|
NProgress.done() // hack: https://github.com/PanJiaChen/vue-element-admin/pull/2939
|
|
|
} else {
|
|
|
// determine whether the user has obtained his permission roles through getInfo
|
|
|
@@ -34,7 +39,7 @@ router.beforeEach(async(to, from, next) => {
|
|
|
try {
|
|
|
// get user info
|
|
|
// note: roles must be a object array! such as: ['admin'] or ,['developer','editor']
|
|
|
- const { pages } = await store.dispatch('user/getInfo')
|
|
|
+ const {pages} = await store.dispatch('user/getInfo')
|
|
|
// generate accessible routes map based on roles
|
|
|
const accessRoutes = await store.dispatch('permission/generateRoutes', pages)
|
|
|
// dynamically add accessible routes
|
|
|
@@ -42,12 +47,12 @@ router.beforeEach(async(to, from, next) => {
|
|
|
|
|
|
// hack method to ensure that addRoutes is complete
|
|
|
// set the replace: true, so the navigation will not leave a history record
|
|
|
- next({ ...to, replace: true })
|
|
|
+ next({...to, replace: true})
|
|
|
} catch (error) {
|
|
|
// remove token and go to login page to re-login
|
|
|
await store.dispatch('user/resetToken')
|
|
|
Message.error(error || 'Has Error')
|
|
|
- next(`/login?redirect=${to.path}`)
|
|
|
+ next(`/dashboard-screen`)
|
|
|
NProgress.done()
|
|
|
}
|
|
|
}
|