JGuang

Breadcrumb

Breadcrumb · Ant Design

Preview
npm install antd@6.6.5 @ant-design/icons@6.3.4 dayjs@1.11.23

Breadcrumb

Display the current location within a hierarchy. And allow going back to states higher up in the hierarchy.

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.

Examples

  • Basic Usage · basic
  • With an Icon · withIcon
  • With Params · withParams
  • Configuring the Separator · separator
  • Bread crumbs with drop down menu · overlay
  • Configuring the Separator Independently · separator-component
  • Debug Routes · debug-routes
  • Custom semantic dom styling · style-class

API

Common props ref:Common props

PropertyDescriptionTypeDefaultVersionGlobal Config
classNamesCustomize class for each semantic structure inside the component. Supports object or function.Record<SemanticDOM, string> | (info: { props })=> Record<SemanticDOM, string>-6.0.06.0.0
dropdownIconCustom dropdown iconReactNode<DownOutlined />6.2.06.2.0
itemsThe routing stack information of router (>=5.3.0 recommended, use Breadcrumb.Item children for older versions)ItemType[]-5.3.0×
itemRenderCustom item renderer, work with react-router, see example(route, params, routes, paths) => ReactNode-×
paramsRouting parametersobject-×
separatorCustom separatorReactNode/6.0.0
stylesCustomize inline style for each semantic structure inside the component. Supports object or function.Record<SemanticDOM, CSSProperties> | (info: { props })=> Record<SemanticDOM, CSSProperties>-6.0.06.0.0

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-5.3.0

SeparatorType

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.

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

Semantic nodeNative descriptionVersion
rootRoot element with text color, font size, icon size and other basic styles, using flex layout with ordered list6.0.0
itemItem element with text color, link color transitions, hover effects, padding, border-radius, height, and margin styles6.0.0
separatorSeparator element with margin and color styles for the divider6.0.0

Semantic description source: vendor/components/breadcrumb/demo/_semantic.tsx

Design Token

Types, inheritance and declarations retain the pinned native source. Defaults are computed by the native theme and may be overridden by ConfigProvider; this table does not invent static defaults.

TokenTypeNative description
itemColorstringText color of Breadcrumb item
iconFontSizenumberIcon size
linkColorstringText color of link
linkHoverColorstringColor of hovered link
lastItemColorstringText color of the last item
separatorMarginnumberMargin of separator
separatorColorstringColor of separator

Declaration source: vendor/components/breadcrumb/style/index.ts

import { unit } from '@ant-design/cssinjs';

import type { CSSObject } from '@ant-design/cssinjs';

import { genFocusStyle, resetComponent } from '../../style';

import type { FullToken, GenerateStyle, GetDefaultToken } from '../../theme/internal';

import { genStyleHooks, mergeToken } from '../../theme/internal';

export interface ComponentToken {
  /**
   * @desc 面包屑项文字颜色
   * @descEN Text color of Breadcrumb item
   */
  itemColor: string;
  /**
   * @desc 图标大小
   * @descEN Icon size
   */
  iconFontSize: number;
  /**
   * @desc 链接文字颜色
   * @descEN Text color of link
   */
  linkColor: string;
  /**
   * @desc 链接文字悬浮颜色
   * @descEN Color of hovered link
   */
  linkHoverColor: string;
  /**
   * @desc 最后一项文字颜色
   * @descEN Text color of the last item
   */
  lastItemColor: string;
  /**
   * @desc 分隔符外间距
   * @descEN Margin of separator
   */
  separatorMargin: number;
  /**
   * @desc 分隔符颜色
   * @descEN Color of separator
   */
  separatorColor: string;
}

interface BreadcrumbToken extends FullToken<'Breadcrumb'> {}

Shared native props

Tips: The following generic properties apply to most antd components; those not supported are described separately.

PropertyDescriptionTypeDefault
styleThe additional styleCSSProperties-
classNameThe additional css classstring-
rootClassNameClassName on the root elementstring-
autoFocusAuto focus when component mounted, only effective for focusable elements like forms, links, etc.booleanfalse

Install and reproduce an example

npm install antd@6.6.5 @ant-design/icons@6.3.4 dayjs@1.11.23

Use ConfigProvider and native App; configure dayjs locale separately. Each example lists its complete source files and additional pinned dependencies in View code. Example names select demos, not universal component props. See the resource setup guide for theme, locale and SSR.

Native type references

The source viewer includes unchanged native implementations and the following source declarations. Inherited types remain in their native packages. English source comments are preserved as code reference.

  • vendor/components/breadcrumb/Breadcrumb.tsx
  • vendor/components/breadcrumb/BreadcrumbContext.ts
  • vendor/components/breadcrumb/BreadcrumbItem.tsx
  • vendor/components/breadcrumb/BreadcrumbSeparator.tsx
  • vendor/components/breadcrumb/index.tsx
  • vendor/components/breadcrumb/style/index.ts
  • vendor/components/breadcrumb/useItemRender.tsx
  • vendor/components/breadcrumb/useItems.ts

Source and license

https://github.com/ant-design/ant-design/tree/4a39f54842eade4e565ab336ef6097cd7e723cdd

Original bilingual prose and executable examples are retained. Website-only embeds and token tables are expanded locally. Ant Design is MIT; separately listed dependency notices also apply. Upload previews block outbound requests and do not provide a backend.