index.js
1.14 KB
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({ name, id, routesData }) {
// const routes = []
// if (routesData && name && id) {
// for (let i = 0, length = routesData.length; i < length; i += 1) {
// const element = routesData[i]
// if (element && element.path && element.path.includes(name) && element.meta && element.meta.id && element.meta.id.startsWith(id)) {
// const path = element.path.slice(name.length + 1)
// element.path = path
// element.component = () => import('@/views' + path + '.vue')
// routes.push(element)
// }
// }
// }
// return routes
// }
function getRoutes(routesData) {
return routesData.reduce((routes, route) => {
routes.push({ ...route, component: () => import('@/views' + route.path + '.vue') })
return routes
}, [])
}
export { VueRouter, routes, getRoutes }