diff --git a/src/components/PageHeader/index.js b/src/components/PageHeader/index.js index 80f5fc36598872b85b8f8b2988f6036e55ca4259..e9002a0c070049aaa8668cafea6bf793672272c6 100644 --- a/src/components/PageHeader/index.js +++ b/src/components/PageHeader/index.js @@ -6,16 +6,23 @@ import styles from './index.less'; const { TabPane } = Tabs; -function getBreadcrumbNameWithParams(breadcrumbNameMap, url) { - let name = ''; +function getBreadcrumbName(breadcrumbNameMap, url) { + if (breadcrumbNameMap[url] && breadcrumbNameMap[url].name) { + return breadcrumbNameMap[url].name; + } + const urlWithoutSplash = url.replace(/\/$/, ''); + if (breadcrumbNameMap[urlWithoutSplash] && breadcrumbNameMap[urlWithoutSplash].name) { + return breadcrumbNameMap[urlWithoutSplash].name; + } + let breadcrumbName = ''; Object.keys(breadcrumbNameMap).forEach((item) => { const itemRegExpStr = `^${item.replace(/:[\w-]+/g, '[\\w-]+')}$`; const itemRegExp = new RegExp(itemRegExpStr); if (itemRegExp.test(url)) { - name = breadcrumbNameMap[item]; + breadcrumbName = breadcrumbNameMap[item].name; } }); - return name; + return breadcrumbName || url; } export default class PageHeader extends PureComponent { @@ -72,12 +79,9 @@ export default class PageHeader extends PureComponent { return ( {createElement( - index === pathSnippets.length - 1 ? 'span' : linkElement, + (index === pathSnippets.length - 1) ? 'span' : linkElement, { [linkElement === 'a' ? 'href' : 'to']: url }, - breadcrumbNameMap[url] || - breadcrumbNameMap[url.replace('/', '')] || - getBreadcrumbNameWithParams(breadcrumbNameMap, url) || - url + getBreadcrumbName(breadcrumbNameMap, url), )} ); diff --git a/src/layouts/BasicLayout.js b/src/layouts/BasicLayout.js index 180cec75e322b15107c28bbe993069309f3c1e13..a46cb5728c6a4cbca0550609defed4daf4c4f753 100644 --- a/src/layouts/BasicLayout.js +++ b/src/layouts/BasicLayout.js @@ -61,7 +61,10 @@ class BasicLayout extends React.PureComponent { const breadcrumbNameMap = {}; routeData.concat(menuData).forEach((item) => { - breadcrumbNameMap[item.path] = item.name; + breadcrumbNameMap[item.path] = { + name: item.name, + component: item.component, + }; }); return { location, breadcrumbNameMap }; }