|
|
|
---
|
|
|
|
category: Components
|
|
|
|
subtitle: 面包屑
|
|
|
|
group: 导航
|
|
|
|
title: Breadcrumb
|
|
|
|
cover: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*I5a2Tpqs3y0AAAAAAAAAAAAADrJ8AQ/original
|
|
|
|
demo:
|
|
|
|
cols: 2
|
|
|
|
---
|
|
|
|
|
|
|
|
显示当前页面在系统层级结构中的位置,并能向上返回。
|
|
|
|
|
|
|
|
## 何时使用
|
|
|
|
|
|
|
|
- 当系统拥有超过两级以上的层级结构时;
|
|
|
|
- 当需要告知用户『你在哪里』时;
|
|
|
|
- 当需要向上导航的功能时。
|
|
|
|
|
|
|
|
## 代码演示
|
|
|
|
|
|
|
|
<!-- prettier-ignore -->
|
|
|
|
<code src="./demo/basic.tsx">基本</code>
|
|
|
|
<code src="./demo/withIcon.tsx">带有图标的</code>
|
|
|
|
<code src="./demo/react-router.tsx" iframe="200">react-router V6</code>
|
|
|
|
<code src="./demo/separator.tsx">分隔符</code>
|
|
|
|
<code src="./demo/overlay.tsx">带下拉菜单的面包屑</code>
|
|
|
|
<code src="./demo/separator-component.tsx">分隔符</code>
|
|
|
|
|
|
|
|
## API
|
|
|
|
|
|
|
|
### Breadcrumb
|
|
|
|
|
|
|
|
| 参数 | 说明 | 类型 | 默认值 | 版本 |
|
|
|
|
| --- | --- | --- | --- | --- |
|
|
|
|
| itemRender | 自定义链接函数,和 react-router 配置使用 | (route, params, routes, paths) => ReactNode | - | |
|
|
|
|
| params | 路由的参数 | object | - | |
|
|
|
|
| routes | router 的路由栈信息 | [routes\[\]](#routes) | - | |
|
|
|
|
| separator | 分隔符自定义 | ReactNode | `/` | |
|
|
|
|
|
|
|
|
### Breadcrumb.Item
|
|
|
|
|
|
|
|
| 参数 | 说明 | 类型 | 默认值 | 版本 |
|
|
|
|
| --- | --- | --- | --- | --- |
|
|
|
|
| className | 自定义类名 | string | - | |
|
|
|
|
| dropdownProps | 弹出下拉菜单的自定义配置 | [Dropdown](/components/dropdown-cn) | - | |
|
|
|
|
| href | 链接的目的地 | string | - | |
|
|
|
|
| menu | 菜单配置项 | [MenuProps](/components/menu-cn/#api) | - | 4.24.0 |
|
|
|
|
| onClick | 单击事件 | (e:MouseEvent) => void | - | |
|
|
|
|
|
|
|
|
### Breadcrumb.Separator
|
|
|
|
|
|
|
|
| 参数 | 说明 | 类型 | 默认值 | 版本 |
|
|
|
|
| -------- | -------------- | --------- | ------ | ---- |
|
|
|
|
| children | 要显示的分隔符 | ReactNode | `/` | |
|
|
|
|
|
|
|
|
> 注意:在使用 `Breadcrumb.Separator` 时,其父组件的分隔符必须设置为 `separator=""`,否则会出现父组件默认的分隔符。
|
|
|
|
|
|
|
|
### routes
|
|
|
|
|
|
|
|
```ts
|
|
|
|
interface Route {
|
|
|
|
path: string;
|
|
|
|
breadcrumbName: string;
|
|
|
|
children: Array<{
|
|
|
|
path: string;
|
|
|
|
breadcrumbName: string;
|
|
|
|
}>;
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
### 和 browserHistory 配合
|
|
|
|
|
|
|
|
和 react-router 一起使用时,默认生成的 url 路径是带有 `#` 的,如果和 browserHistory 一起使用的话,你可以使用 `itemRender` 属性定义面包屑链接。
|
|
|
|
|
|
|
|
```jsx
|
|
|
|
import { Link } from 'react-router';
|
|
|
|
|
|
|
|
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',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
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>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return <Breadcrumb itemRender={itemRender} routes={routes} />;
|
|
|
|
```
|