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'; ...@@ -6,6 +6,18 @@ import styles from './index.less';
const { TabPane } = Tabs; 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 { export default class PageHeader extends PureComponent {
static contextTypes = { static contextTypes = {
routes: PropTypes.array, routes: PropTypes.array,
...@@ -59,9 +71,14 @@ export default class PageHeader extends PureComponent { ...@@ -59,9 +71,14 @@ export default class PageHeader extends PureComponent {
const url = `/${pathSnippets.slice(0, index + 1).join('/')}`; const url = `/${pathSnippets.slice(0, index + 1).join('/')}`;
return ( return (
<Breadcrumb.Item key={url}> <Breadcrumb.Item key={url}>
{createElement(index === pathSnippets.length - 1 ? 'span' : linkElement, { {createElement(
[linkElement === 'a' ? 'href' : 'to']: url, index === pathSnippets.length - 1 ? 'span' : linkElement,
}, breadcrumbNameMap[url] || breadcrumbNameMap[url.replace('/', '')] || url)} { [linkElement === 'a' ? 'href' : 'to']: url },
breadcrumbNameMap[url] ||
breadcrumbNameMap[url.replace('/', '')] ||
getBreadcrumbNameWithParams(breadcrumbNameMap, url) ||
url
)}
</Breadcrumb.Item> </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