From 9a34d47c66ffd35ec341eb755ccf6b3417f09a5a Mon Sep 17 00:00:00 2001 From: Reed Sun Date: Sat, 24 Mar 2018 12:06:35 +0800 Subject: [PATCH] Improve the display of bread crumbs (#1053) * Improve the display of bread crumbs * unuse template literals --- src/layouts/BasicLayout.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/layouts/BasicLayout.js b/src/layouts/BasicLayout.js index 60339b99..6ee29894 100644 --- a/src/layouts/BasicLayout.js +++ b/src/layouts/BasicLayout.js @@ -38,6 +38,25 @@ const getRedirect = (item) => { }; getMenuData().forEach(getRedirect); +/** + * 获取面包屑映射 + * @param {Object} menuData 菜单配置 + * @param {Object} routerData 路由配置 + */ +const getBreadcrumbNameMap = (menuData, routerData) => { + const result = {}; + const childResult = {}; + for (const i of menuData) { + if (!routerData[i.path]) { + result[i.path] = i; + } + if (i.children) { + Object.assign(childResult, getBreadcrumbNameMap(i.children, routerData)); + } + } + return Object.assign({}, routerData, result, childResult); +}; + const query = { 'screen-xs': { maxWidth: 575, @@ -76,7 +95,7 @@ class BasicLayout extends React.PureComponent { const { location, routerData } = this.props; return { location, - breadcrumbNameMap: routerData, + breadcrumbNameMap: getBreadcrumbNameMap(getMenuData(), routerData), }; } componentDidMount() { -- GitLab