2016-03-31 14:17:09 +08:00
|
|
|
---
|
|
|
|
category: Components
|
2016-09-21 11:28:38 +08:00
|
|
|
subtitle: 面包屑
|
2018-11-04 16:20:35 +08:00
|
|
|
type: 导航
|
2016-09-21 11:28:38 +08:00
|
|
|
title: Breadcrumb
|
2020-05-31 11:48:34 +08:00
|
|
|
cover: https://gw.alipayobjects.com/zos/alicdn/9Ltop8JwH/Breadcrumb.svg
|
2016-03-31 14:17:09 +08:00
|
|
|
---
|
2015-06-15 22:01:39 +08:00
|
|
|
|
2015-06-26 14:42:30 +08:00
|
|
|
显示当前页面在系统层级结构中的位置,并能向上返回。
|
2015-06-17 20:24:42 +08:00
|
|
|
|
2015-06-26 14:42:30 +08:00
|
|
|
## 何时使用
|
2015-06-17 20:24:42 +08:00
|
|
|
|
2015-06-26 14:42:30 +08:00
|
|
|
- 当系统拥有超过两级以上的层级结构时;
|
2016-02-18 11:31:49 +08:00
|
|
|
- 当需要告知用户『你在哪里』时;
|
2015-06-26 14:42:30 +08:00
|
|
|
- 当需要向上导航的功能时。
|
2015-09-15 17:35:22 +08:00
|
|
|
|
|
|
|
## API
|
|
|
|
|
2019-05-06 12:04:39 +08:00
|
|
|
### Breadcrumb
|
|
|
|
|
2019-07-11 14:14:33 +08:00
|
|
|
| 参数 | 说明 | 类型 | 默认值 | 版本 |
|
|
|
|
| --- | --- | --- | --- | --- |
|
2019-11-20 18:10:44 +08:00
|
|
|
| itemRender | 自定义链接函数,和 react-router 配置使用 | (route, params, routes, paths) => ReactNode | - | |
|
|
|
|
| params | 路由的参数 | object | - | |
|
|
|
|
| routes | router 的路由栈信息 | [routes\[\]](#routes) | - | |
|
2020-06-30 11:25:55 +08:00
|
|
|
| separator | 分隔符自定义 | string \| ReactNode | `/` | |
|
2019-05-06 12:04:39 +08:00
|
|
|
|
|
|
|
### Breadcrumb.Item
|
|
|
|
|
2020-03-09 17:18:32 +08:00
|
|
|
| 参数 | 说明 | 类型 | 默认值 | 版本 |
|
|
|
|
| --- | --- | --- | --- | --- |
|
|
|
|
| href | 链接的目的地 | string | - | |
|
|
|
|
| overlay | 下拉菜单的内容 | [Menu](/components/menu) \| () => Menu | - | |
|
|
|
|
| onClick | 单击事件 | (e:MouseEvent)=>void | - | |
|
|
|
|
| dropdownProps | 弹出下拉菜单的自定义配置 | [Dropdown](/components/dropdown) | - | |
|
2019-05-06 12:04:39 +08:00
|
|
|
|
2019-11-20 18:10:44 +08:00
|
|
|
### Breadcrumb.Separator
|
2019-07-31 15:00:00 +08:00
|
|
|
|
2020-06-30 11:25:55 +08:00
|
|
|
| 参数 | 说明 | 类型 | 默认值 | 版本 |
|
|
|
|
| -------- | -------------- | ------------------- | ------ | ---- |
|
|
|
|
| children | 要显示的分隔符 | string \| ReactNode | `/` | |
|
2019-07-31 15:00:00 +08:00
|
|
|
|
|
|
|
> 注意:在使用 `Breadcrumb.Separator` 时,其父组件的分隔符必须设置为 `separator=""`,否则会出现父组件默认的分隔符。
|
|
|
|
|
2019-05-06 12:04:39 +08:00
|
|
|
### routes
|
|
|
|
|
|
|
|
```ts
|
|
|
|
interface Route {
|
|
|
|
path: string;
|
|
|
|
breadcrumbName: string;
|
|
|
|
children: Array<{
|
|
|
|
path: string;
|
|
|
|
breadcrumbName: string;
|
|
|
|
}>;
|
|
|
|
}
|
|
|
|
```
|
2016-08-29 16:52:35 +08:00
|
|
|
|
2016-12-04 15:17:17 +08:00
|
|
|
### 和 browserHistory 配合
|
|
|
|
|
|
|
|
和 react-router 一起使用时,默认生成的 url 路径是带有 `#` 的,如果和 browserHistory 一起使用的话,你可以使用 `itemRender` 属性定义面包屑链接。
|
|
|
|
|
|
|
|
```jsx
|
|
|
|
import { Link } from 'react-router';
|
|
|
|
|
2019-05-06 12:04:39 +08:00
|
|
|
const routes = [
|
|
|
|
{
|
|
|
|
path: 'index',
|
|
|
|
breadcrumbName: 'home',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: 'first',
|
|
|
|
breadcrumbName: 'first',
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
path: '/general',
|
|
|
|
breadcrumbName: 'General',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: '/layout',
|
|
|
|
breadcrumbName: 'Layout',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: '/navigation',
|
|
|
|
breadcrumbName: 'Navigation',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
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;
|
2019-05-06 12:04:39 +08:00
|
|
|
return last ? (
|
|
|
|
<span>{route.breadcrumbName}</span>
|
|
|
|
) : (
|
|
|
|
<Link to={paths.join('/')}>{route.breadcrumbName}</Link>
|
|
|
|
);
|
2016-12-04 15:17:17 +08:00
|
|
|
}
|
|
|
|
|
2019-05-06 12:04:39 +08:00
|
|
|
return <Breadcrumb itemRender={itemRender} routes={routes} />;
|
2016-12-04 15:17:17 +08:00
|
|
|
```
|