|
@@ -4,11 +4,16 @@ import { Message } from 'element-ui' |
|
@@ -4,11 +4,16 @@ import { Message } from 'element-ui' |
|
4
|
import NProgress from 'nprogress'
|
4
|
import NProgress from 'nprogress'
|
|
5
|
import 'nprogress/nprogress.css'
|
5
|
import 'nprogress/nprogress.css'
|
|
6
|
import { getToken } from '@/utils/auth'
|
6
|
import { getToken } from '@/utils/auth'
|
|
|
|
7
|
+import { isPathMatch } from '@/utils/validate'
|
|
7
|
import { isRelogin } from '@/utils/request'
|
8
|
import { isRelogin } from '@/utils/request'
|
|
8
|
|
9
|
|
|
9
|
NProgress.configure({ showSpinner: false })
|
10
|
NProgress.configure({ showSpinner: false })
|
|
10
|
|
11
|
|
|
11
|
-const whiteList = ['/login', '/register']
|
12
|
+const whiteList = ['/login', '/register', '/register*', '/register/*']
|
|
|
|
13
|
+
|
|
|
|
14
|
+const isWhiteList = (path) => {
|
|
|
|
15
|
+ return whiteList.some(pattern => isPathMatch(pattern, path))
|
|
|
|
16
|
+}
|
|
12
|
|
17
|
|
|
13
|
router.beforeEach((to, from, next) => {
|
18
|
router.beforeEach((to, from, next) => {
|
|
14
|
NProgress.start()
|
19
|
NProgress.start()
|
|
@@ -18,7 +23,7 @@ router.beforeEach((to, from, next) => { |
|
@@ -18,7 +23,7 @@ router.beforeEach((to, from, next) => { |
|
18
|
if (to.path === '/login') {
|
23
|
if (to.path === '/login') {
|
|
19
|
next({ path: '/' })
|
24
|
next({ path: '/' })
|
|
20
|
NProgress.done()
|
25
|
NProgress.done()
|
|
21
|
- } else if (whiteList.indexOf(to.path) !== -1) {
|
26
|
+ } else if (isWhiteList(to.path)) {
|
|
22
|
next()
|
27
|
next()
|
|
23
|
} else {
|
28
|
} else {
|
|
24
|
if (store.getters.roles.length === 0) {
|
29
|
if (store.getters.roles.length === 0) {
|
|
@@ -43,7 +48,7 @@ router.beforeEach((to, from, next) => { |
|
@@ -43,7 +48,7 @@ router.beforeEach((to, from, next) => { |
|
43
|
}
|
48
|
}
|
|
44
|
} else {
|
49
|
} else {
|
|
45
|
// 没有token
|
50
|
// 没有token
|
|
46
|
- if (whiteList.indexOf(to.path) !== -1) {
|
51
|
+ if (isWhiteList(to.path)) {
|
|
47
|
// 在免登录白名单,直接进入
|
52
|
// 在免登录白名单,直接进入
|
|
48
|
next()
|
53
|
next()
|
|
49
|
} else {
|
54
|
} else {
|