index.js
1.3 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import Vue from 'vue'
import store from '@/store'
import VueRouter from 'vue-router'
import { deepCopy } from "@libs/tools"
import { filterAsyncRouter } from "@libs/filterAsyncRouter"
const routerPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
return routerPush.call(this, location).catch(error=> error)
}
import util from '@/libs/util.js'
// 路由数据
import routes from './routes'
Vue.use(VueRouter)
// 导出路由 在 main.js 里使用
const router = new VueRouter({
routes
})
/**
* 路由拦截
* 权限验证
*/
router.beforeEach((to, from, next) => {
// let permission_routes = store.state.permission_routes.menusList, routesList = []
// if(to.name!='login' && permission_routes.length===0&& util.cookies.get('menusList')){
// let list = JSON.parse(util.cookies.get('menusList'))
// routesList = deepCopy(list)
// }else{
// routesList = deepCopy(permission_routes)
// }
// 动态路由
// 验证当前路由所有的匹配中是否需要有登录验证的
// const token = util.cookies.get('token')
// if (token && token !== 'undefined') {
// next()
// } else {
// next({
// name: 'textRouter1',
// query: {
// redirect: to.fullPath
// }
// })
// }
next()
})
export default router