From d4f10ee5cae24382e7703184e0047471a3b1aa94 Mon Sep 17 00:00:00 2001 From: ddcat1115 Date: Fri, 10 Nov 2017 17:44:24 +0800 Subject: [PATCH] fix #128 --- src/layouts/BasicLayout.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/layouts/BasicLayout.js b/src/layouts/BasicLayout.js index 9a0237bf..2e9ec908 100644 --- a/src/layouts/BasicLayout.js +++ b/src/layouts/BasicLayout.js @@ -55,8 +55,10 @@ class BasicLayout extends React.PureComponent { getChildContext() { const { location } = this.props; const routeData = getRouteData('BasicLayout'); - const menuData = getNavData().reduce((arr, current) => arr.concat(current.children), []); + const firstMenuData = getNavData().reduce((arr, current) => arr.concat(current.children), []); + const menuData = this.getMenuData(firstMenuData, ''); const breadcrumbNameMap = {}; + routeData.concat(menuData).forEach((item) => { breadcrumbNameMap[item.path] = item.name; }); @@ -83,6 +85,16 @@ class BasicLayout extends React.PureComponent { }); } } + getMenuData = (data, parentPath) => { + let arr = []; + data.forEach((item) => { + if (item.children) { + arr.push({ path: `${parentPath}/${item.path}`, name: item.name }); + arr = arr.concat(this.getMenuData(item.children, `${parentPath}/${item.path}`)); + } + }); + return arr; + } getDefaultCollapsedSubMenus(props) { const currentMenuSelectedKeys = [...this.getCurrentMenuSelectedKeys(props)]; currentMenuSelectedKeys.splice(-1, 1); -- GitLab