diff --git a/src/layouts/BasicLayout.js b/src/layouts/BasicLayout.js index 60339b9905d24ae35eaebd0222a74ab608ad68fc..6ee298944320a26ac1de4145bc1cc89b3dd1716a 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() {