2016-06-19 11:14:21 +08:00
|
|
|
|
---
|
|
|
|
|
category: Components
|
|
|
|
|
type: Navigation
|
|
|
|
|
title: Breadcrumb
|
|
|
|
|
---
|
|
|
|
|
|
2016-11-29 17:13:24 +08:00
|
|
|
|
A breadcrumb displays the current location within a hierarchy. It allows going back to states higher up in the hierarchy.
|
2016-06-19 11:14:21 +08:00
|
|
|
|
|
2016-09-10 13:43:30 +08:00
|
|
|
|
## When To Use
|
2016-06-19 11:14:21 +08:00
|
|
|
|
|
|
|
|
|
- When the system has more than two layers in a hierarchy.
|
|
|
|
|
- When you need to inform the user of where they are.
|
2016-11-29 17:13:24 +08:00
|
|
|
|
- When the user may need to navigate back to a higher level.
|
|
|
|
|
- When the application has multi-layer architecture.
|
2016-06-19 11:14:21 +08:00
|
|
|
|
|
|
|
|
|
## API
|
|
|
|
|
|
2017-10-25 10:25:44 +08:00
|
|
|
|
| Property | Description | Type | Optional | Default |
|
|
|
|
|
| -------- | ----------- | ---- | -------- | ------- |
|
|
|
|
|
| itemRender | Custom item renderer | (route, params, routes, paths) => ReactNode | | - |
|
|
|
|
|
| params | Routing parameters | object | | - |
|
|
|
|
|
| routes | The routing stack information of router | object\[] | | - |
|
|
|
|
|
| separator | Custom separator | string\|ReactNode | | `/` |
|
2016-08-29 16:52:35 +08:00
|
|
|
|
|
2016-12-04 15:17:17 +08:00
|
|
|
|
### Use with browserHistory
|
|
|
|
|
|
2017-09-08 09:43:43 +08:00
|
|
|
|
The link of Breadcrumb item targets `#` by default, you can use `itemRender` to make a `browserHistory` Link.
|
2016-12-04 15:17:17 +08:00
|
|
|
|
|
|
|
|
|
```jsx
|
|
|
|
|
import { Link } from 'react-router';
|
|
|
|
|
|
2017-10-19 22:36:49 +08:00
|
|
|
|
const routes = [{
|
|
|
|
|
path: 'index',
|
|
|
|
|
breadcrumbName: 'home'
|
|
|
|
|
}, {
|
|
|
|
|
path: 'first',
|
|
|
|
|
breadcrumbName: 'first'
|
|
|
|
|
}, {
|
|
|
|
|
path: 'second',
|
|
|
|
|
breadcrumbName: 'second'
|
|
|
|
|
}];
|
2016-12-04 15:17:17 +08:00
|
|
|
|
function itemRender(route, params, routes, paths) {
|
|
|
|
|
const last = routes.indexOf(route) === routes.length - 1;
|
|
|
|
|
return last ? <span>{route.breadcrumbName}</span> : <Link to={paths.join('/')}>{route.breadcrumbName}</Link>;
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-19 22:36:49 +08:00
|
|
|
|
return <Breadcrumb itemRender={itemRender} routes={routes} />;
|
2016-12-04 15:17:17 +08:00
|
|
|
|
```
|