Breadcrumb
面包屑

显示当前页面在系统层级结构中的位置,并能向上返回。
使用import{ Breadcrumb }from"antd";

何时使用

  • 当系统拥有超过两级以上的层级结构时;
  • 当需要告知用户『你在哪里』时;
  • 当需要向上导航的功能时。
// >=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' }]} />;

代码演示

API

通用属性参考:通用属性

参数说明类型默认值版本
itemRender自定义链接函数,和 react-router 配置使用(route, params, routes, paths) => ReactNode-
params路由的参数object-
items路由栈信息items[]-5.3.0
separator分隔符自定义ReactNode/

ItemType

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

RouteItemType

参数说明类型默认值版本
className自定义类名string-
dropdownProps弹出下拉菜单的自定义配置Dropdown-
href链接的目的地,不能和 path 共用string-
path拼接路径,每一层都会拼接前一个 path 信息。不能和 href 共用string-
menu菜单配置项MenuProps-4.24.0
onClick单击事件(e:MouseEvent) => void-
title名称ReactNode-5.3.0

SeparatorType

const item = {
type: 'separator', // Must have
separator: '/',
};
参数说明类型默认值版本
type标记为分隔符separator5.3.0
separator要显示的分隔符ReactNode/5.3.0

和 browserHistory 配合

和 react-router 一起使用时,默认生成的 url 路径是带有 # 的,如果和 browserHistory 一起使用的话,你可以使用 itemRender 属性定义面包屑链接。

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} />;

主题变量(Design Token)

组件 Token如何定制?

Token 名称描述类型默认值
iconFontSize图标大小number14
itemColor面包屑项文字颜色stringrgba(0,0,0,0.45)
lastItemColor最后一项文字颜色stringrgba(0,0,0,0.88)
linkColor链接文字颜色stringrgba(0,0,0,0.45)
linkHoverColor链接文字悬浮颜色stringrgba(0,0,0,0.88)
separatorColor分隔符颜色stringrgba(0,0,0,0.45)
separatorMargin分隔符外间距number8

全局 Token如何定制?