diff --git a/components/breadcrumb/Breadcrumb.jsx b/components/breadcrumb/Breadcrumb.jsx index fe74ad494b..c59582981a 100644 --- a/components/breadcrumb/Breadcrumb.jsx +++ b/components/breadcrumb/Breadcrumb.jsx @@ -1,12 +1,24 @@ import React, { cloneElement } from 'react'; import BreadcrumbItem from './BreadcrumbItem'; +const defaultNameFormatter = (route, params) => { + if (!route.breadcrumbName) { + return null; + } + const name = route.breadcrumbName.replace(/:(.*)/g, (replacement, key) => { + return params[key] || replacement; + }); + + return name; +}; + export default class Breadcrumb extends React.Component { static defaultProps = { prefixCls: 'ant-breadcrumb', separator: '/', - linkRender: (href, name) => {name}, + linkRender: (paths, name) => {name}, nameRender: (name) => {name}, + nameFormatter: defaultNameFormatter, } static propTypes = { @@ -19,13 +31,15 @@ export default class Breadcrumb extends React.Component { params: React.PropTypes.object, linkRender: React.PropTypes.func, nameRender: React.PropTypes.func, + nameFormatter: React.PropTypes.func, } render() { let crumbs; - const { separator, prefixCls, routes, params, children, linkRender, nameRender } = this.props; + const { separator, prefixCls, routes, params, children, linkRender, nameRender, nameFormatter } = this.props; if (routes && routes.length > 0) { const paths = []; + const lastPath = routes.length - 1; crumbs = routes.map((route, i) => { route.path = route.path || ''; let path = route.path.replace(/^\//, ''); @@ -36,20 +50,13 @@ export default class Breadcrumb extends React.Component { paths.push(path); } - if (!route.breadcrumbName) { - return null; + const name = nameFormatter(route, params); + if (name) { + const link = (i === lastPath) ? nameRender(name) : linkRender(paths, name); + return {link}; } - const name = route.breadcrumbName.replace(/:(.*)/g, (replacement, key) => { - return params[key] || replacement; - }); - let link; - if (i === routes.length - 1) { - link = nameRender(name); - } else { - link = linkRender(`/${paths.join('/')}`, name); - } - return {link}; + return null; }); } else { crumbs = React.Children.map(children, (element, index) => {