2016-06-19 11:14:21 +08:00
|
|
|
|
---
|
|
|
|
|
category: Components
|
2022-11-09 12:28:04 +08:00
|
|
|
|
group: Navigation
|
2016-06-19 11:14:21 +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-06-19 11:14:21 +08:00
|
|
|
|
---
|
|
|
|
|
|
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.
|
2016-06-19 11:14:21 +08:00
|
|
|
|
|
2023-03-05 20:57:49 +08:00
|
|
|
|
```jsx
|
|
|
|
|
// works when >=5.3.0, recommended ✅
|
|
|
|
|
return <Breadcrumb items={[{ title: 'sample' }]} />;
|
|
|
|
|
|
|
|
|
|
// works when <5.3.0, deprecated when >=5.3.0 🙅🏻♀️
|
|
|
|
|
return (
|
|
|
|
|
<Breadcrumb>
|
|
|
|
|
<Breadcrumb.Item>sample</Breadcrumb.Item>
|
|
|
|
|
</Breadcrumb>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// or
|
|
|
|
|
|
|
|
|
|
return <Breadcrumb routes={[{ breadcrumbName: 'sample' }]} />;
|
|
|
|
|
```
|
|
|
|
|
|
2022-11-09 12:28:04 +08:00
|
|
|
|
## Examples
|
|
|
|
|
|
2022-11-17 17:31:26 +08:00
|
|
|
|
<!-- prettier-ignore -->
|
2022-11-09 12:28:04 +08:00
|
|
|
|
<code src="./demo/basic.tsx">Basic Usage</code>
|
|
|
|
|
<code src="./demo/withIcon.tsx">With an Icon</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">Configuring the Separator</code>
|
|
|
|
|
<code src="./demo/overlay.tsx">Bread crumbs with drop down menu</code>
|
2023-03-30 16:37:52 +08:00
|
|
|
|
<code src="./demo/separator-component.tsx">Configuring the Separator Independently</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>Component Token</code>
|
2022-11-09 12:28:04 +08:00
|
|
|
|
|
2016-06-19 11:14:21 +08:00
|
|
|
|
## API
|
|
|
|
|
|
2023-08-08 18:27:48 +08:00
|
|
|
|
Common props ref:[Common props](/docs/react/common-props)
|
|
|
|
|
|
2019-11-20 18:10:44 +08:00
|
|
|
|
### Breadcrumb
|
|
|
|
|
|
2022-11-17 17:31:26 +08:00
|
|
|
|
| Property | Description | Type | Default | Version |
|
|
|
|
|
| --- | --- | --- | --- | --- |
|
|
|
|
|
| itemRender | Custom item renderer | (route, params, routes, paths) => ReactNode | - | |
|
|
|
|
|
| params | Routing parameters | object | - | |
|
2023-03-05 20:57:49 +08:00
|
|
|
|
| items | The routing stack information of router | [items\[\]](#ItemType) | - | 5.3.0 |
|
2022-11-17 17:31:26 +08:00
|
|
|
|
| separator | Custom separator | ReactNode | `/` | |
|
2019-11-20 18:10:44 +08:00
|
|
|
|
|
2023-03-05 20:57:49 +08:00
|
|
|
|
### ItemType
|
|
|
|
|
|
|
|
|
|
> type ItemType = [RouteItemType](#RouteItemType) | [SeparatorType](#SeparatorType)
|
|
|
|
|
|
|
|
|
|
### RouteItemType
|
2019-11-20 18:10:44 +08:00
|
|
|
|
|
2022-11-17 17:31:26 +08:00
|
|
|
|
| Property | Description | Type | Default | Version |
|
|
|
|
|
| --- | --- | --- | --- | --- |
|
|
|
|
|
| className | The additional css class | string | - | |
|
|
|
|
|
| dropdownProps | The dropdown props | [Dropdown](/components/dropdown) | - | |
|
2023-04-27 22:43:42 +08:00
|
|
|
|
| href | Target of hyperlink. Can not work with `path` | string | - | |
|
|
|
|
|
| path | Connected path. Each path will connect with prev one. Can not work with `href` | string | - | |
|
2022-12-22 14:12:26 +08:00
|
|
|
|
| menu | The menu props | [MenuProps](/components/menu/#api) | - | 4.24.0 |
|
2022-11-17 17:31:26 +08:00
|
|
|
|
| onClick | Set the handler to handle click event | (e:MouseEvent) => void | - | |
|
2023-03-05 20:57:49 +08:00
|
|
|
|
| title | item name | ReactNode | - | |
|
2019-11-20 18:10:44 +08:00
|
|
|
|
|
2023-03-05 20:57:49 +08:00
|
|
|
|
### SeparatorType
|
2019-11-20 18:10:44 +08:00
|
|
|
|
|
|
|
|
|
```ts
|
2023-03-05 20:57:49 +08:00
|
|
|
|
const item = {
|
|
|
|
|
type: 'separator', // Must have
|
|
|
|
|
separator: '/',
|
|
|
|
|
};
|
2019-11-20 18:10:44 +08:00
|
|
|
|
```
|
2016-08-29 16:52:35 +08:00
|
|
|
|
|
2023-03-05 20:57:49 +08:00
|
|
|
|
| Property | Description | Type | Default | Version |
|
|
|
|
|
| --------- | ----------------- | ----------- | ------- | ------- |
|
|
|
|
|
| type | Mark as separator | `separator` | | 5.3.0 |
|
|
|
|
|
| separator | Custom separator | ReactNode | `/` | 5.3.0 |
|
|
|
|
|
|
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';
|
|
|
|
|
|
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(route, 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
|
|
|
|
|
|
|
|
|
## Design Token
|
|
|
|
|
|
|
|
|
|
<ComponentTokenTable component="Breadcrumb"></ComponentTokenTable>
|