const routesMap = {
address: './views/',
data: ["Entrance", {
path: "Index",
children: {
address: './views/childs/',
data: [{
path: "Index",
component: "Home"
}, "Home", "QQ", "WeChat", "TikTok", "Personal", "Authorization",
"GroupSend", "Assignment", "Script", "ApplyUpdates", "Equipment", "DeviceGroup"
]
}
}]
}
const VueRouterPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(to) {
return VueRouterPush.call(this, to).catch(err => err)
}
function routes(Map) {
let routesChildren = []
for (let Item in Map.data) {
if ((typeof Map.data[Item]) == "string") {
routesChildren.push({
path: '/' + Map.data[Item],
component: eval(`() => import("${Map.address}${Map.data[Item]}.js")`)
})
} else {
routesChildren.push({
path: '/' + Map.data[Item].path,
component: eval(
`() => import("${Map.address}${Map.data[Item].component||Map.data[Item].path}.js")`),
children: Map.data[Item].children ? routes(Map.data[Item].children) : null
})
}
}
return routesChildren
}
export default new VueRouter({
routes: routes(routesMap)
});
|