Showing
1 changed file
with
35 additions
and
10 deletions
| ... | @@ -169,6 +169,10 @@ function setRoute(route, childrens) { | ... | @@ -169,6 +169,10 @@ function setRoute(route, childrens) { |
| 169 | return route; | 169 | return route; |
| 170 | } | 170 | } |
| 171 | 171 | ||
| 172 | +function isValidMenuPath(p) { | ||
| 173 | + return p != null && String(p).trim() !== ""; | ||
| 174 | +} | ||
| 175 | + | ||
| 172 | function routeItemInfo(data) { | 176 | function routeItemInfo(data) { |
| 173 | const routes = [ | 177 | const routes = [ |
| 174 | { | 178 | { |
| ... | @@ -207,15 +211,22 @@ function routeItemInfo(data) { | ... | @@ -207,15 +211,22 @@ function routeItemInfo(data) { |
| 207 | ]; | 211 | ]; |
| 208 | 212 | ||
| 209 | data.forEach((item) => { | 213 | data.forEach((item) => { |
| 210 | - const isParent = item.parentId == 0 && item.children.length == 0; | 214 | + const rawChildren = item.children || []; |
| 211 | - const route = { | 215 | + const isParent = item.parentId == 0 && rawChildren.length == 0; |
| 212 | - path: item.path, | 216 | + if (!isValidMenuPath(item.path)) { |
| 213 | - component: "Layout", | 217 | + console.warn("[permission] skip menu item without path:", item); |
| 214 | - alwaysShow: true, | 218 | + return; |
| 215 | - hidden: false, | 219 | + } |
| 216 | - meta: { title: item.name, icon: item.icon }, | 220 | + const childRoutes = !isParent |
| 217 | - children: !isParent | 221 | + ? rawChildren |
| 218 | - ? item.children.map((child) => ({ | 222 | + .filter((child) => { |
| 223 | + if (!isValidMenuPath(child.path)) { | ||
| 224 | + console.warn("[permission] skip child menu without path:", child); | ||
| 225 | + return false; | ||
| 226 | + } | ||
| 227 | + return true; | ||
| 228 | + }) | ||
| 229 | + .map((child) => ({ | ||
| 219 | path: child.path, | 230 | path: child.path, |
| 220 | component: `${child.path}`, | 231 | component: `${child.path}`, |
| 221 | hidden: false, | 232 | hidden: false, |
| ... | @@ -230,7 +241,21 @@ function routeItemInfo(data) { | ... | @@ -230,7 +241,21 @@ function routeItemInfo(data) { |
| 230 | name: item.name, | 241 | name: item.name, |
| 231 | meta: { title: item.name, icon: item.icon || "" }, | 242 | meta: { title: item.name, icon: item.icon || "" }, |
| 232 | }, | 243 | }, |
| 233 | - ], | 244 | + ]; |
| 245 | + if (!isParent && childRoutes.length === 0) { | ||
| 246 | + console.warn( | ||
| 247 | + "[permission] skip menu with no valid child paths:", | ||
| 248 | + item.path | ||
| 249 | + ); | ||
| 250 | + return; | ||
| 251 | + } | ||
| 252 | + const route = { | ||
| 253 | + path: item.path, | ||
| 254 | + component: "Layout", | ||
| 255 | + alwaysShow: true, | ||
| 256 | + hidden: false, | ||
| 257 | + meta: { title: item.name, icon: item.icon }, | ||
| 258 | + children: childRoutes, | ||
| 234 | }; | 259 | }; |
| 235 | routes.push(route); | 260 | routes.push(route); |
| 236 | }); | 261 | }); | ... | ... |
-
Please register or login to post a comment