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-10-09 10:08:52 +08:00
|
|
|
| separator | 分隔符自定义 | ReactNode | `/` | |
|
2019-05-06 12:04:39 +08:00
|
|
|
|
|
|
|
### Breadcrumb.Item
|
|
|
|
|
2020-03-09 17:18:32 +08:00
|
|
|
| 参数 | 说明 | 类型 | 默认值 | 版本 |
|
|
|
|
| --- | --- | --- | --- | --- |
|
2020-12-09 09:54:44 +08:00
|
|
|
| className | 自定义类名 | string | - | |
|
2020-08-05 14:50:52 +08:00
|
|
|
| dropdownProps | 弹出下拉菜单的自定义配置 | [Dropdown](/components/dropdown) | - | |
|
2020-03-09 17:18:32 +08:00
|
|
|
| href | 链接的目的地 | string | - | |
|
2020-08-18 17:53:21 +08:00
|
|
|
| overlay | 下拉菜单的内容 | [Menu](/components/menu) \| () => Menu | - | |
|
2020-10-21 10:33:43 +08:00
|
|
|
| onClick | 单击事件 | (e:MouseEvent) => void | - | |
|
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
|
|
|
|
2021-03-01 19:20:48 +08:00
|
|
|
| 参数 | 说明 | 类型 | 默认值 | 版本 |
|
|
|
|
| --- | --- | --- | --- | --- |
|
|
|
|
| children | 要显示的分隔符 | 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
|
|
|
```
|