asyncRouter.js 807 Bytes
/*
 * @Description:
 * @Autor: renchao
 * @LastEditTime: 2023-03-21 14:45:26
 */
import Vue from 'vue'
import Layout from '@/layout'
const config = require('/public/config.json')
console.log(config, 'Vue.2222222222222.BASE_API');
export default function filterAsyncRouter (routers) {
  routers.forEach(item => {
    if (!item.children) {
      delete item.children
    } else {
      item.children = filterAsyncRouter(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
    }
  })
  return routers
}
function loadView (view) {
  return r => require.ensure([], () => r(require(`@/views${view}.vue`)))
}