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
| import router from '@/router/page/index'
| import {
| getToken
| } from './utils/auth'
|
| router.beforeEach((to, from, next) => {
| console.log(to.path)
| const meta = to.meta || {}
| if (getToken()) {
| if (to.path === '/login') { // 如果登录成功访问登录页跳转到主页
| next({
| path: '/'
| })
| } else {
| next()
| }
| } else {
| // 判断是否需要认证,没有登录访问去登录页
| if (meta.isAuth === false) {
| next()
| } else {
| next('/login')
| }
| }
| })
|
|