Back to Ant Design

Breadcrumb

components/breadcrumb/index.en-US.md

6.3.74.3 KB
Original Source

When To Use

  • When the system has more than two layers in a hierarchy.
  • When you need to inform the user of where they are.
  • When the user may need to navigate back to a higher level.
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' }]} />;

Examples

<!-- prettier-ignore -->

<code src="./demo/basic.tsx">Basic Usage</code> <code src="./demo/withIcon.tsx">With an Icon</code> <code src="./demo/withParams.tsx">With Params</code> <code src="./demo/separator.tsx">Configuring the Separator</code> <code src="./demo/overlay.tsx">Bread crumbs with drop down menu</code> <code src="./demo/separator-component.tsx">Configuring the Separator Independently</code> <code src="./demo/debug-routes.tsx">Debug Routes</code> <code src="./demo/style-class.tsx" version="6.0.0">Custom semantic dom styling</code> <code src="./demo/component-token.tsx" debug>Component Token</code>

API

Common props ref:Common props

PropertyDescriptionTypeDefaultVersion
classNamesCustomize class for each semantic structure inside the component. Supports object or function.Record<SemanticDOM, string> | (info: { props })=> Record<SemanticDOM, string>-
dropdownIconCustom dropdown iconReactNode<DownOutlined />6.2.0
itemRenderCustom item renderer(route, params, routes, paths) => ReactNode-
paramsRouting parametersobject-
itemsThe routing stack information of routerItemType[]-5.3.0
separatorCustom separatorReactNode/
stylesCustomize inline style for each semantic structure inside the component. Supports object or function.Record<SemanticDOM, CSSProperties> | (info: { props })=> Record<SemanticDOM, CSSProperties>-

ItemType

type ItemType = Omit<RouteItemType, 'title' | 'path'> | SeparatorType

RouteItemType

PropertyDescriptionTypeDefaultVersion
classNameThe additional css classstring-
dropdownPropsThe dropdown propsDropdown-
hrefTarget of hyperlink. Can not work with pathstring-
pathConnected path. Each path will connect with prev one. Can not work with hrefstring-
menuThe menu propsMenuProps-4.24.0
onClickSet the handler to handle click event(e:MouseEvent) => void-
titleitem nameReactNode-

SeparatorType

ts
const item = {
  type: 'separator', // Must have
  separator: '/',
};
PropertyDescriptionTypeDefaultVersion
typeMark as separatorseparator5.3.0
separatorCustom separatorReactNode/5.3.0

Use with browserHistory

The link of Breadcrumb item targets # by default, you can use itemRender to make a browserHistory Link.

jsx
import { Link } from 'react-router';

const items = [
  {
    path: '/index',
    title: 'home',
  },
  {
    path: '/first',
    title: 'first',
    children: [
      {
        path: '/general',
        title: 'General',
      },
      {
        path: '/layout',
        title: 'Layout',
      },
      {
        path: '/navigation',
        title: 'Navigation',
      },
    ],
  },
  {
    path: '/second',
    title: 'second',
  },
];

function itemRender(currentRoute, params, items, paths) {
  const isLast = currentRoute?.path === items[items.length - 1]?.path;

  return isLast ? (
    <span>{currentRoute.title}</span>
  ) : (
    <Link to={`/${paths.join('/')}`}>{currentRoute.title}</Link>
  );
}

return <Breadcrumb itemRender={itemRender} items={items} />;

Semantic DOM

<code src="./demo/_semantic.tsx" simplify="true"></code>

Design Token

<ComponentTokenTable component="Breadcrumb"></ComponentTokenTable>