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