Skip to content

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

Description

@cage-taofei

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

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 = 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
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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