Skip to content

SideMenu的getMenuItem方法处理,会导致目录下只有一个子菜单的时候,只显示子菜单,不显示父目录的问题解决办法 #86

@3352671160

Description

@3352671160

function getMenuItem(route, basePath = '') {
let menuItem = {
label: (route.meta && route.meta.title) || route.name,
key: route.name,
path: resolvePath(basePath, route.path),
icon: getIcon(route.meta),
order: route.meta?.order || 0,
}

const visibleChildren = route.children
? route.children.filter((item) => item.name && !item.isHidden)
: []

if (!visibleChildren.length) return menuItem

menuItem.children = visibleChildren
.map((item) => getMenuItem(item, menuItem.path))
.sort((a, b) => a.order - b.order)

// if (visibleChildren.length === 1) {
// // 单个子路由处理
// const singleRoute = visibleChildren[0]
// menuItem = {
// ...menuItem,
// label: singleRoute.meta?.title || singleRoute.name,
// key: singleRoute.name,
// path: resolvePath(menuItem.path, singleRoute.path),
// icon: getIcon(singleRoute.meta),
// }
// const visibleItems = singleRoute.children
// ? singleRoute.children.filter((item) => item.name && !item.isHidden)
// : []

// if (visibleItems.length === 1) {
// menuItem.children = getMenuItem(visibleItems[0], menuItem.path)
// } else if (visibleItems.length > 1) {
// menuItem.children = visibleItems
// .map((item) => getMenuItem(item, menuItem.path))
// .sort((a, b) => a.order - b.order)
// }
// } else {
// menuItem.children = visibleChildren
// .map((item) => getMenuItem(item, menuItem.path))
// .sort((a, b) => a.order - b.order)
// }
return menuItem
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions