asyncRouter.js
786 Bytes
import Layout from '@/layout'
export default function filterAsyncRouter (routers) {
routers.forEach(item => {
if (!item.children) {
delete item.children
}
item.path = JSON.parse(item.metadata).path
if (!item.parentId) {
item.component = Layout
} else {
item.component = loadView(item.uri)
}
item.meta = {
title: item.name,
icon: item.icon
}
if (item.children) {
item.children = filterAsyncRouter(item.children)
if (item.path !== '/') {
item.redirect = item.path + '/' + item.children[0].path
} else {
item.redirect = '/' + item.children[0].path
}
}
})
return routers
}
function loadView (view) {
return r => require.ensure([], () => r(require(`@/views${view}.vue`)))
}