From 1a46c6e9aa0f341dd59809dec9daa1ae3c31ac34 Mon Sep 17 00:00:00 2001 From: hzq Date: Thu, 8 Mar 2018 10:34:47 +0800 Subject: [PATCH] Update SiderMenu.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 当权限子菜单无权限或不存在子菜单时不展示父菜单 --- src/components/SiderMenu/SiderMenu.js | 38 +++++++++++++++------------ 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/src/components/SiderMenu/SiderMenu.js b/src/components/SiderMenu/SiderMenu.js index 072f5cea..f9abebcd 100644 --- a/src/components/SiderMenu/SiderMenu.js +++ b/src/components/SiderMenu/SiderMenu.js @@ -113,23 +113,27 @@ export default class SiderMenu extends PureComponent { */ getSubMenuOrItem = (item) => { if (item.children && item.children.some(child => child.name)) { - return ( - - {getIcon(item.icon)} - {item.name} - - ) : ( - item.name - ) - } - key={item.path} - > - {this.getNavMenuItems(item.children)} - - ); + const childrenItems = this.getNavMenuItems(item.children); + // 当无子菜单时就不展示菜单 + if (childrenItems && childrenItems.length > 0) { + return ( + + {getIcon(item.icon)} + {item.name} + + ) : ( + item.name + ) + } + key={item.path} + > + {childrenItems} + + ) + } } else { return ( {this.getMenuItemPath(item)} -- GitLab