jinhui.wang

路由path空数据处理逻辑增加

......@@ -169,6 +169,10 @@ function setRoute(route, childrens) {
return route;
}
function isValidMenuPath(p) {
return p != null && String(p).trim() !== "";
}
function routeItemInfo(data) {
const routes = [
{
......@@ -207,15 +211,22 @@ function routeItemInfo(data) {
];
data.forEach((item) => {
const isParent = item.parentId == 0 && item.children.length == 0;
const route = {
path: item.path,
component: "Layout",
alwaysShow: true,
hidden: false,
meta: { title: item.name, icon: item.icon },
children: !isParent
? item.children.map((child) => ({
const rawChildren = item.children || [];
const isParent = item.parentId == 0 && rawChildren.length == 0;
if (!isValidMenuPath(item.path)) {
console.warn("[permission] skip menu item without path:", item);
return;
}
const childRoutes = !isParent
? rawChildren
.filter((child) => {
if (!isValidMenuPath(child.path)) {
console.warn("[permission] skip child menu without path:", child);
return false;
}
return true;
})
.map((child) => ({
path: child.path,
component: `${child.path}`,
hidden: false,
......@@ -230,7 +241,21 @@ function routeItemInfo(data) {
name: item.name,
meta: { title: item.name, icon: item.icon || "" },
},
],
];
if (!isParent && childRoutes.length === 0) {
console.warn(
"[permission] skip menu with no valid child paths:",
item.path
);
return;
}
const route = {
path: item.path,
component: "Layout",
alwaysShow: true,
hidden: false,
meta: { title: item.name, icon: item.icon },
children: childRoutes,
};
routes.push(route);
});
......