Browse Source

Merge branch 'plandem-master'

pull/2007/head
afc163 9 years ago
parent
commit
203b1ef388
  1. 34
      components/breadcrumb/Breadcrumb.jsx
  2. 4
      components/breadcrumb/index.md

34
components/breadcrumb/Breadcrumb.jsx

@ -1,12 +1,22 @@
import React, { cloneElement } from 'react';
import BreadcrumbItem from './BreadcrumbItem';
const defaultNameRender = (breadcrumbName, route, params) => {
if (!breadcrumbName) {
return null;
}
const name = breadcrumbName.replace(
/:(.*)/g, (replacement, key) => params[key] || replacement
);
return <span>{name}</span>;
};
export default class Breadcrumb extends React.Component {
static defaultProps = {
prefixCls: 'ant-breadcrumb',
separator: '/',
linkRender: (href, name) => <a href={`#${href}`}>{name}</a>,
nameRender: (name) => <span>{name}</span>,
linkRender: (paths, name) => <a href={`#/${paths.join('/')}`}>{name}</a>,
nameRender: defaultNameRender,
}
static propTypes = {
@ -26,6 +36,7 @@ export default class Breadcrumb extends React.Component {
const { separator, prefixCls, routes, params, children, linkRender, nameRender } = 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(/^\//, '');
@ -35,21 +46,12 @@ export default class Breadcrumb extends React.Component {
if (path) {
paths.push(path);
}
if (!route.breadcrumbName) {
return null;
}
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);
const name = nameRender(route.breadcrumbName, route, params);
if (name) {
const link = (i === lastPath) ? name : linkRender(paths, name);
return <BreadcrumbItem separator={separator} key={route.breadcrumbName || i}>{link}</BreadcrumbItem>;
}
return <BreadcrumbItem separator={separator} key={name}>{link}</BreadcrumbItem>;
return null;
});
} else {
crumbs = React.Children.map(children, (element, index) => {

4
components/breadcrumb/index.md

@ -29,5 +29,5 @@ english: Breadcrumb
| routes | router 的路由栈信息 | Array | | - |
| params | 路由的参数 | Object | | - |
| separator | 分隔符自定义 | String or Element | | '/' |
| linkRender | 自定义链接函数,和 react-router 配置使用 | Function(href, name) | | - |
| nameRender | 自定义链接函数,和 react-router 配置使用 | Function(name) | | - |
| linkRender | 自定义链接函数,和 react-router 配置使用 | Function(href, breadcrumbName) | | - |
| nameRender | 自定义文字函数,和 react-router 配置使用 | Function(breadcrumbName, route, params) | | - |

Loading…
Cancel
Save