2016-03-31 14:17:09 +08:00
|
|
|
|
---
|
|
|
|
|
category: Components
|
2016-09-21 11:28:38 +08:00
|
|
|
|
subtitle: 面包屑
|
2022-11-09 12:28:04 +08:00
|
|
|
|
group: 导航
|
2016-09-21 11:28:38 +08:00
|
|
|
|
title: Breadcrumb
|
2022-11-30 20:14:41 +08:00
|
|
|
|
cover: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*I5a2Tpqs3y0AAAAAAAAAAAAADrJ8AQ/original
|
2023-02-09 22:17:31 +08:00
|
|
|
|
coverDark: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*Tr90QKrE_LcAAAAAAAAAAAAADrJ8AQ/original
|
2022-11-09 12:28:04 +08:00
|
|
|
|
demo:
|
|
|
|
|
cols: 2
|
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
|
|
|
|
|
2023-03-05 20:57:49 +08:00
|
|
|
|
```jsx
|
|
|
|
|
// >=5.3.0 可用,推荐的写法 ✅
|
|
|
|
|
return <Breadcrumb items={[{ title: 'sample' }]} />;
|
|
|
|
|
|
|
|
|
|
// <5.3.0 可用,>=5.3.0 时不推荐 🙅🏻♀️
|
|
|
|
|
return (
|
|
|
|
|
<Breadcrumb>
|
|
|
|
|
<Breadcrumb.Item>sample</Breadcrumb.Item>
|
|
|
|
|
</Breadcrumb>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// 或
|
|
|
|
|
|
|
|
|
|
return <Breadcrumb routes={[{ breadcrumbName: 'sample' }]} />;
|
|
|
|
|
```
|
|
|
|
|
|
2022-11-09 12:28:04 +08:00
|
|
|
|
## 代码演示
|
|
|
|
|
|
2022-11-17 17:31:26 +08:00
|
|
|
|
<!-- prettier-ignore -->
|
2022-11-09 12:28:04 +08:00
|
|
|
|
<code src="./demo/basic.tsx">基本</code>
|
|
|
|
|
<code src="./demo/withIcon.tsx">带有图标的</code>
|
2022-11-17 11:30:20 +08:00
|
|
|
|
<code src="./demo/react-router.tsx" iframe="200">react-router V6</code>
|
2022-11-09 12:28:04 +08:00
|
|
|
|
<code src="./demo/separator.tsx">分隔符</code>
|
|
|
|
|
<code src="./demo/overlay.tsx">带下拉菜单的面包屑</code>
|
2023-03-30 16:37:52 +08:00
|
|
|
|
<code src="./demo/separator-component.tsx">独立的分隔符</code>
|
2023-03-05 20:57:49 +08:00
|
|
|
|
<code src="./demo/debug-routes.tsx">Debug Routes</code>
|
2023-05-18 16:32:52 +08:00
|
|
|
|
<code src="./demo/component-token.tsx" debug>组件 Token</code>
|
2022-11-09 12:28:04 +08:00
|
|
|
|
|
2015-09-15 17:35:22 +08:00
|
|
|
|
## API
|
|
|
|
|
|
2023-08-08 18:27:48 +08:00
|
|
|
|
通用属性参考:[通用属性](/docs/react/common-props)
|
|
|
|
|
|
2019-05-06 12:04:39 +08:00
|
|
|
|
### Breadcrumb
|
|
|
|
|
|
2022-11-17 17:31:26 +08:00
|
|
|
|
| 参数 | 说明 | 类型 | 默认值 | 版本 |
|
|
|
|
|
| --- | --- | --- | --- | --- |
|
|
|
|
|
| itemRender | 自定义链接函数,和 react-router 配置使用 | (route, params, routes, paths) => ReactNode | - | |
|
|
|
|
|
| params | 路由的参数 | object | - | |
|
2023-03-05 20:57:49 +08:00
|
|
|
|
| items | 路由栈信息 | [items\[\]](#ItemType) | - | 5.3.0 |
|
2022-11-17 17:31:26 +08:00
|
|
|
|
| separator | 分隔符自定义 | ReactNode | `/` | |
|
2019-05-06 12:04:39 +08:00
|
|
|
|
|
2023-03-05 20:57:49 +08:00
|
|
|
|
### ItemType
|
|
|
|
|
|
|
|
|
|
> type ItemType = [RouteItemType](#RouteItemType) | [SeparatorType](#SeparatorType)
|
|
|
|
|
|
|
|
|
|
### RouteItemType
|
2019-05-06 12:04:39 +08:00
|
|
|
|
|
2022-12-13 15:49:05 +08:00
|
|
|
|
| 参数 | 说明 | 类型 | 默认值 | 版本 |
|
|
|
|
|
| --- | --- | --- | --- | --- |
|
|
|
|
|
| className | 自定义类名 | string | - | |
|
|
|
|
|
| dropdownProps | 弹出下拉菜单的自定义配置 | [Dropdown](/components/dropdown-cn) | - | |
|
2023-04-27 22:43:42 +08:00
|
|
|
|
| href | 链接的目的地,不能和 `path` 共用 | string | - | |
|
|
|
|
|
| path | 拼接路径,每一层都会拼接前一个 `path` 信息。不能和 `href` 共用 | string | - | |
|
2022-12-22 14:12:26 +08:00
|
|
|
|
| menu | 菜单配置项 | [MenuProps](/components/menu-cn/#api) | - | 4.24.0 |
|
2022-12-13 15:49:05 +08:00
|
|
|
|
| onClick | 单击事件 | (e:MouseEvent) => void | - | |
|
2023-03-05 20:57:49 +08:00
|
|
|
|
| title | 名称 | ReactNode | - | 5.3.0 |
|
2019-05-06 12:04:39 +08:00
|
|
|
|
|
2023-03-05 20:57:49 +08:00
|
|
|
|
### SeparatorType
|
2019-05-06 12:04:39 +08:00
|
|
|
|
|
|
|
|
|
```ts
|
2023-03-05 20:57:49 +08:00
|
|
|
|
const item = {
|
|
|
|
|
type: 'separator', // Must have
|
|
|
|
|
separator: '/',
|
|
|
|
|
};
|
2019-05-06 12:04:39 +08:00
|
|
|
|
```
|
2016-08-29 16:52:35 +08:00
|
|
|
|
|
2023-03-05 20:57:49 +08:00
|
|
|
|
| 参数 | 说明 | 类型 | 默认值 | 版本 |
|
|
|
|
|
| --------- | -------------- | ----------- | ------ | ----- |
|
|
|
|
|
| type | 标记为分隔符 | `separator` | | 5.3.0 |
|
|
|
|
|
| separator | 要显示的分隔符 | ReactNode | `/` | 5.3.0 |
|
|
|
|
|
|
2016-12-04 15:17:17 +08:00
|
|
|
|
### 和 browserHistory 配合
|
|
|
|
|
|
|
|
|
|
和 react-router 一起使用时,默认生成的 url 路径是带有 `#` 的,如果和 browserHistory 一起使用的话,你可以使用 `itemRender` 属性定义面包屑链接。
|
|
|
|
|
|
|
|
|
|
```jsx
|
|
|
|
|
import { Link } from 'react-router';
|
|
|
|
|
|
2023-03-05 20:57:49 +08:00
|
|
|
|
const items = [
|
2019-05-06 12:04:39 +08:00
|
|
|
|
{
|
|
|
|
|
path: 'index',
|
2023-03-05 20:57:49 +08:00
|
|
|
|
title: 'home',
|
2019-05-06 12:04:39 +08:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: 'first',
|
2023-03-05 20:57:49 +08:00
|
|
|
|
title: 'first',
|
2019-05-06 12:04:39 +08:00
|
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
path: '/general',
|
2023-03-05 20:57:49 +08:00
|
|
|
|
title: 'General',
|
2019-05-06 12:04:39 +08:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: '/layout',
|
2023-03-05 20:57:49 +08:00
|
|
|
|
title: 'Layout',
|
2019-05-06 12:04:39 +08:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: '/navigation',
|
2023-03-05 20:57:49 +08:00
|
|
|
|
title: 'Navigation',
|
2019-05-06 12:04:39 +08:00
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: 'second',
|
2023-03-05 20:57:49 +08:00
|
|
|
|
title: 'second',
|
2019-05-06 12:04:39 +08:00
|
|
|
|
},
|
|
|
|
|
];
|
2023-03-05 20:57:49 +08:00
|
|
|
|
function itemRender(item, params, items, paths) {
|
|
|
|
|
const last = items.indexOf(item) === items.length - 1;
|
|
|
|
|
return last ? <span>{item.title}</span> : <Link to={paths.join('/')}>{item.title}</Link>;
|
2016-12-04 15:17:17 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-03-05 20:57:49 +08:00
|
|
|
|
return <Breadcrumb itemRender={itemRender} items={items} />;
|
2016-12-04 15:17:17 +08:00
|
|
|
|
```
|
2023-03-27 15:33:22 +08:00
|
|
|
|
|
2023-08-30 23:02:35 +08:00
|
|
|
|
## 主题变量(Design Token)
|
2023-03-27 15:33:22 +08:00
|
|
|
|
|
|
|
|
|
<ComponentTokenTable component="Breadcrumb"></ComponentTokenTable>
|