index.js 1.3 KB
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