index.js
560 Bytes
import Vue from 'vue'
import VueRouter from 'vue-router'
import routes from './routes'
Vue.use(VueRouter)
// 处理重复点击同一个路由报错的问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
return originalPush.call(this, location).catch(err => err)
}
function getRoutes(routesData) {
return routesData.reduce((routes, route) => {
routes.push({ ...route, component: () => import('@/views' + route.compath + '.vue') })
return routes
}, [])
}
export { VueRouter, routes, getRoutes }