Skip to main content

Breadcrumb

Breadcrumb displays the current location within a hierarchy.

When To Use

  • When the system has multiple layers of hierarchy
  • When you need to inform the user of where they are
  • When you need to provide quick navigation to parent pages

Basic Usage

import { TxBreadcrumb } from "tx-design-ui";

const items = [
{
key: "home",
label: "Home",
href: "/",
},
{
key: "category",
label: "Category",
href: "/category",
},
{
key: "product",
label: "Product",
},
];

<TxBreadcrumb items={items} />;

Custom Separator

Change the separator between breadcrumb items.

<TxBreadcrumb items={items} separator=">" />
<TxBreadcrumb items={items} separator="-" />
<TxBreadcrumb items={items} separator="" />

Display breadcrumbs without navigation links.

const items = [
{
key: "home",
label: "Home",
},
{
key: "category",
label: "Category",
},
{
key: "product",
label: "Product",
},
];

<TxBreadcrumb items={items} />;

With Icons

Add icons to breadcrumb items.

const items = [
{
key: "home",
label: (
<>
<HomeIcon /> Home
</>
),
href: "/",
},
{
key: "user",
label: (
<>
<UserIcon /> Users
</>
),
href: "/users",
},
{
key: "profile",
label: "Profile",
},
];

Dynamic Breadcrumb

Generate breadcrumb items from route path.

function Example() {
const location = useLocation();
const pathSnippets = location.pathname.split("/").filter(i => i);

const items = pathSnippets.map((snippet, index) => {
const url = `/${pathSnippets.slice(0, index + 1).join("/")}`;
return {
key: url,
label: snippet,
href: index < pathSnippets.length - 1 ? url : undefined,
};
});

return <TxBreadcrumb items={[{ key: "home", label: "Home", href: "/" }, ...items]} />;
}

API

PropertyTypeDefaultDescription
itemsArray<BreadcrumbItem>[]Breadcrumb items
separatorReactNode'/'Custom separator
PropertyTypeDefaultDescription
keystring-Unique key
labelReactNode-Item label (required)
hrefstring-Link URL (optional)

Notes

  • The last breadcrumb item is not clickable by default
  • Use href property to make items clickable
  • Breadcrumb should be placed near the top of the page
  • Keep breadcrumb labels concise and meaningful
  • Consider mobile responsiveness when having many items