2015-07-01 20:44:19 +08:00
|
|
|
import React from 'react';
|
|
|
|
|
|
|
|
let prefixCls = 'ant-breadcrumb';
|
|
|
|
|
|
|
|
let BreadcrumbItem = React.createClass({
|
2015-09-01 16:18:46 +08:00
|
|
|
propTypes: {
|
|
|
|
href: React.PropTypes.string
|
|
|
|
},
|
2015-07-01 20:44:19 +08:00
|
|
|
render() {
|
2015-09-01 16:18:46 +08:00
|
|
|
let link = <a className={prefixCls + '-link'} {...this.props}>{this.props.children}</a>;
|
|
|
|
let slash = <span className={prefixCls + '-slash'}>/</span>;
|
2015-07-01 20:44:19 +08:00
|
|
|
if (typeof this.props.href === 'undefined') {
|
|
|
|
link = <span className={prefixCls + '-link'} {...this.props}>{this.props.children}</span>;
|
|
|
|
}
|
2015-07-02 17:22:26 +08:00
|
|
|
return <span>{link}{slash}</span>;
|
2015-07-01 20:44:19 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
let Breadcrumb = React.createClass({
|
2015-09-01 16:18:46 +08:00
|
|
|
propTypes: {
|
2015-09-15 17:35:22 +08:00
|
|
|
router: React.PropTypes.object,
|
|
|
|
routes: React.PropTypes.array,
|
|
|
|
params: React.PropTypes.object
|
2015-07-02 17:22:26 +08:00
|
|
|
},
|
2015-07-01 20:44:19 +08:00
|
|
|
render() {
|
2015-09-15 17:35:22 +08:00
|
|
|
let crumbs;
|
2015-08-20 19:52:56 +08:00
|
|
|
let ReactRouter = this.props.router;
|
2015-09-15 17:35:22 +08:00
|
|
|
let routes = this.props.routes;
|
|
|
|
let params = this.props.params;
|
|
|
|
if (routes && routes.length > 0 && ReactRouter) {
|
2015-09-01 16:18:46 +08:00
|
|
|
let Link = ReactRouter.Link;
|
2015-07-02 18:33:37 +08:00
|
|
|
crumbs = routes.map(function(route, i) {
|
2015-11-23 11:01:17 +08:00
|
|
|
if (!route.breadcrumbName) {
|
|
|
|
return null;
|
|
|
|
}
|
2015-09-01 16:18:46 +08:00
|
|
|
let name = route.breadcrumbName.replace(/\:(.*)/g, function(replacement, key) {
|
2015-07-02 18:05:34 +08:00
|
|
|
return params[key] || replacement;
|
|
|
|
});
|
2015-09-01 16:18:46 +08:00
|
|
|
let link;
|
2015-09-15 17:35:22 +08:00
|
|
|
let path = route.path.indexOf('/') === 0 ? route.path : ('/' + route.path);
|
2015-07-02 18:33:37 +08:00
|
|
|
if (i === routes.length - 1) {
|
|
|
|
link = <span>{name}</span>;
|
|
|
|
} else {
|
2015-09-15 17:35:22 +08:00
|
|
|
link = <Link to={path} params={params}>{name}</Link>;
|
2015-07-02 18:33:37 +08:00
|
|
|
}
|
2015-07-09 18:23:34 +08:00
|
|
|
return <BreadcrumbItem key={name}>{link}</BreadcrumbItem>;
|
2015-07-02 17:22:26 +08:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
crumbs = this.props.children;
|
2015-07-01 21:24:04 +08:00
|
|
|
}
|
2015-07-01 20:44:19 +08:00
|
|
|
return (
|
|
|
|
<div className={prefixCls}>
|
2015-07-02 17:22:26 +08:00
|
|
|
{crumbs}
|
2015-07-01 20:44:19 +08:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Breadcrumb.Item = BreadcrumbItem;
|
|
|
|
export default Breadcrumb;
|