Blame view

src/utils/asyncRouter.js 689 Bytes
任超 committed
1 2 3 4 5
/*
 * @Description: 
 * @Autor: renchao
 * @LastEditTime: 2023-03-07 09:35:10
 */
任超 committed
6 7 8 9 10 11 12 13
import Layout from '@/layout'
export default function filterAsyncRouter (routers) {
  routers.forEach(item => {
    if (!item.children) {
      delete item.children
    } else {
      item.children = filterAsyncRouter(item.children)
    }
任超 committed
14
    item.path = JSON.parse(item.metadata)?.path || '/'
任超 committed
15 16 17 18 19 20 21 22 23 24 25 26 27 28
    if (!item.parentId) {
      item.component = Layout
    } else {
      item.component = loadView(item.uri)
    }
    item.meta = {
      title: item.name,
      icon: item.icon
    }
  })
  return routers
}
function loadView (view) {
  return r => require.ensure([], () => r(require(`@/views${view}.vue`)))
xiaomiao committed
29
}