fix: 修复动态路由子级长度为0时抛出异常 (#333)

This commit is contained in:
SampsonYe(叶飞) 2022-08-23 10:10:49 +08:00 committed by GitHub
parent 1ed598c5f2
commit 3baffa11e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -230,16 +230,18 @@ function addAsyncRoutes(arrRoutes: Array<RouteRecordRaw>) {
// 将backstage属性加入meta标识此路由为后端返回路由
v.meta.backstage = true;
// 父级的redirect属性取值如果子级存在且父级的redirect属性不存在默认取第一个子级的path如果子级存在且父级的redirect属性存在取存在的redirect属性会覆盖默认值
if (v?.children && !v.redirect) v.redirect = v.children[0].path;
if (v?.children && v.children.length && !v.redirect)
v.redirect = v.children[0].path;
// 父级的name属性取值如果子级存在且父级的name属性不存在默认取第一个子级的name如果子级存在且父级的name属性存在取存在的name属性会覆盖默认值
if (v?.children && !v.name) v.name = v.children[0].name;
if (v?.children && v.children.length && !v.name)
v.name = v.children[0].name;
if (v.meta?.frameSrc) v.component = IFrame;
// 对后端传component组件路径和不传做兼容如果后端传component组件路径那么path可以随便写如果不传component组件路径会跟path保持一致
const index = v?.component
? modulesRoutesKeys.findIndex(ev => ev.includes(v.component as any))
: modulesRoutesKeys.findIndex(ev => ev.includes(v.path));
v.component = modulesRoutes[modulesRoutesKeys[index]];
if (v.children) {
if (v?.children && v.children.length) {
addAsyncRoutes(v.children);
}
});