Commit c771ea29 authored by ddcat1115's avatar ddcat1115

PageHeader - breadcrumb support url with params

fix #64
parent 7efcab1b
......@@ -6,6 +6,18 @@ import styles from './index.less';
const { TabPane } = Tabs;
function getBreadcrumbNameWithParams(breadcrumbNameMap, url) {
let name = '';
Object.keys(breadcrumbNameMap).forEach((item) => {
const itemRegExpStr = `^${item.replace(/:[\w-]+/g, '[\\w-]+')}$`;
const itemRegExp = new RegExp(itemRegExpStr);
if (itemRegExp.test(url)) {
name = breadcrumbNameMap[item];
}
});
return name;
}
export default class PageHeader extends PureComponent {
static contextTypes = {
routes: PropTypes.array,
......@@ -59,9 +71,14 @@ export default class PageHeader extends PureComponent {
const url = `/${pathSnippets.slice(0, index + 1).join('/')}`;
return (
<Breadcrumb.Item key={url}>
{createElement(index === pathSnippets.length - 1 ? 'span' : linkElement, {
[linkElement === 'a' ? 'href' : 'to']: url,
}, breadcrumbNameMap[url] || breadcrumbNameMap[url.replace('/', '')] || url)}
{createElement(
index === pathSnippets.length - 1 ? 'span' : linkElement,
{ [linkElement === 'a' ? 'href' : 'to']: url },
breadcrumbNameMap[url] ||
breadcrumbNameMap[url.replace('/', '')] ||
getBreadcrumbNameWithParams(breadcrumbNameMap, url) ||
url
)}
</Breadcrumb.Item>
);
});
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment