import Layout from '@/layout'
// 获取组件的方法
const _import = require('./_import_' + process.env.NODE_ENV)

// 动态加载路由
export function filterRouter(asyncRouterMap) {
  const accessedRouters = asyncRouterMap.filter(route => {
    if (route.component) {
      if (route.component === 'Layout') {
        route.component = Layout
      } else {
        route.component = _import(route.component)
      }
    }
    if (route.children && route.children.length) {
      route.children = filterRouter(route.children)
    }
    return true
  })
  return accessedRouters
}
