asyncRouter.js
800 Bytes
/*
* @Description: 动态路由
* @Autor: renchao
* @LastEditTime: 2023-05-16 14:08:42
*/
import Layout from '@/layout'
/**
* @description:
* @param {*} routers
* @author: renchao
*/
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 ? 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`)))
}