logoMogu Design

⌘ K
  • 设计
  • 研发
  • 组件
  • 组件总览
  • 通用
    • Button按钮
    • Icon图标
    • Typography排版
  • 布局
    • Divider分割线
    • Grid栅格
    • Layout布局
    • Space间距
  • 导航
    • Anchor锚点
    • Breadcrumb面包屑
    • Dropdown下拉菜单
    • Menu导航菜单
    • Pagination分页
    • Steps步骤条
  • 数据录入
    • AutoComplete自动完成
    • Cascader级联选择
    • Checkbox多选框
    • ColorPicker颜色选择器New
    • DatePicker日期选择框
    • Form表单
    • Input输入框
    • InputNumber数字输入框
    • Mentions提及
    • Radio单选框
    • Rate评分
    • Select选择器
    • Slider滑动输入条
    • Switch开关
    • TimePicker时间选择框
    • Transfer穿梭框
    • TreeSelect树选择
    • Upload上传
  • 数据展示
    • Avatar头像
    • Badge徽标数
    • Calendar日历
    • Card卡片
    • Carousel走马灯
    • Collapse折叠面板
    • Descriptions描述列表
    • Empty空状态
    • Image图片
    • List列表
    • Popover气泡卡片
    • QRCode二维码
    • Segmented分段控制器
    • Statistic统计数值
    • Table表格
    • Tabs标签页
    • Tag标签
    • Timeline时间轴
    • Tooltip文字提示
    • Tour漫游式引导
    • Tree树形控件
  • 反馈
    • Alert警告提示
    • Drawer抽屉
    • Message全局提示
    • Modal对话框
    • Notification通知提醒框
    • Popconfirm气泡确认框
    • Progress进度条
    • Result结果
    • Skeleton骨架屏
    • Spin加载中
  • 其他
    • Affix固钉
    • App包裹组件
    • ConfigProvider全局化配置
    • FloatButton悬浮按钮
    • Watermark水印
何时使用
代码演示
基本
带有图标的
react-router V6
分隔符
带下拉菜单的面包屑
独立的分隔符
Debug Routes
API
Breadcrumb
ItemType
RouteItemType
SeparatorType
和 browserHistory 配合
Design Token

Breadcrumb面包屑

Anchor锚点Dropdown下拉菜单

显示当前页面在系统层级结构中的位置,并能向上返回。

何时使用

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

代码演示

  1. Home
  2. /
  3. Application Center
  4. /
  5. Application List
  6. /
  7. An Application
基本

最简单的用法。

expand codeexpand code
TypeScript
JavaScript
import React from 'react';
import { Breadcrumb } from 'mogud';

const App: React.FC = () => (
  <Breadcrumb
    items={[
      {
        title: 'Home',
      },
      {
        title: <a href="">Application Center</a>,
      },
      {
        title: <a href="">Application List</a>,
      },
      {
        title: 'An Application',
      },
    ]}
  />
);

export default App;
react-router V6

与 react-router@6+ 结合使用,生成和路由绑定的面包屑。

expand codeexpand code
TypeScript
JavaScript
import React from 'react';
import { Alert, Breadcrumb } from 'mogud';
import { HashRouter, Link, Route, Routes, useLocation } from 'react-router-dom';

const Apps = () => (
  <ul className="app-list">
    <li>
      <Link to="/apps/1">Application1</Link>:<Link to="/apps/1/detail">Detail</Link>
    </li>
    <li>
      <Link to="/apps/2">Application2</Link>:<Link to="/apps/2/detail">Detail</Link>
    </li>
  </ul>
);

const breadcrumbNameMap: Record<string, string> = {
  '/apps': 'Application List',
  '/apps/1': 'Application1',
  '/apps/2': 'Application2',
  '/apps/1/detail': 'Detail',
  '/apps/2/detail': 'Detail',
};

const Home = () => {
  const location = useLocation();
  const pathSnippets = location.pathname.split('/').filter((i) => i);

  const extraBreadcrumbItems = pathSnippets.map((_, index) => {
    const url = `/${pathSnippets.slice(0, index + 1).join('/')}`;
    return {
      key: url,
      title: <Link to={url}>{breadcrumbNameMap[url]}</Link>,
    };
  });

  const breadcrumbItems = [
    {
      title: <Link to="/">Home</Link>,
      key: 'home',
    },
  ].concat(extraBreadcrumbItems);

  return (
    <div className="demo">
      <div className="demo-nav">
        <Link to="/">Home</Link>
        <Link to="/apps">Application List</Link>
      </div>
      <Routes>
        <Route path="/apps" element={<Apps />} />
        <Route path="*" element={<span>Home Page</span>} />
      </Routes>
      <Alert style={{ margin: '16px 0' }} message="Click the navigation above to switch:" />
      <Breadcrumb items={breadcrumbItems} />
    </div>
  );
};

const App: React.FC = () => (
  <HashRouter>
    <Home />
  </HashRouter>
);

export default App;
.demo {
  margin: 16px;
}
.demo-nav {
  height: 30px;
  margin-bottom: 16px;
  line-height: 30px;
  background: #f8f8f8;
}
.demo-nav a {
  padding: 0 8px;
  line-height: 30px;
}
.app-list {
  margin-top: 16px;
}
  1. Ant Design
  2. /
  3. Component
  4. /
  5. General
  6. /
  7. Button
带下拉菜单的面包屑

面包屑支持下拉菜单。

expand codeexpand code
TypeScript
JavaScript
import React from 'react';
import { Breadcrumb } from 'mogud';

const menuItems = [
  {
    key: '1',
    label: (
      <a target="_blank" rel="noopener noreferrer" href="http://www.alipay.com/">
        General
      </a>
    ),
  },
  {
    key: '2',
    label: (
      <a target="_blank" rel="noopener noreferrer" href="http://www.taobao.com/">
        Layout
      </a>
    ),
  },
  {
    key: '3',
    label: (
      <a target="_blank" rel="noopener noreferrer" href="http://www.tmall.com/">
        Navigation
      </a>
    ),
  },
];

const App: React.FC = () => (
  <Breadcrumb
    items={[
      {
        title: 'Ant Design',
      },
      {
        title: <a href="">Component</a>,
      },
      {
        title: <a href="">General</a>,
        menu: { items: menuItems },
      },
      {
        title: 'Button',
      },
    ]}
  />
);

export default App;
  1. Home
  2. /
  3. User
Debug Routes

原 routes 调试。

expand codeexpand code
TypeScript
JavaScript
import { Breadcrumb } from 'mogud';
import React from 'react';

export default () => (
  <Breadcrumb
    routes={[
      {
        path: '/home',
        breadcrumbName: 'Home',
      },
      {
        path: '/user',
        breadcrumbName: 'User',
        children: [
          {
            path: '/user1',
            breadcrumbName: 'User1',
          },
          {
            path: '/user2',
            breadcrumbName: 'User2',
          },
        ],
      },
    ]}
  />
);
  1. /
  2. Application List
  3. /
  4. Application
带有图标的

图标放在文字前面。

expand codeexpand code
TypeScript
JavaScript
import { HomeOutlined, UserOutlined } from '@ant-design/icons';
import { Breadcrumb } from 'mogud';
import React from 'react';

const App: React.FC = () => (
  <Breadcrumb
    items={[
      {
        href: '',
        title: <HomeOutlined />,
      },
      {
        href: '',
        title: (
          <>
            <UserOutlined />
            <span>Application List</span>
          </>
        ),
      },
      {
        title: 'Application',
      },
    ]}
  />
);

export default App;
  1. Home
  2. >
  3. Application Center
  4. >
  5. Application List
  6. >
  7. An Application
分隔符

使用 separator=">" 可以自定义分隔符。

expand codeexpand code
TypeScript
JavaScript
import React from 'react';
import { Breadcrumb } from 'mogud';

const App: React.FC = () => (
  <Breadcrumb
    separator=">"
    items={[
      {
        title: 'Home',
      },
      {
        title: 'Application Center',
        href: '',
      },
      {
        title: 'Application List',
        href: '',
      },
      {
        title: 'An Application',
      },
    ]}
  />
);

export default App;
  1. Location
  2. :
  3. Application Center
  4. /
  5. Application List
  6. /
  7. An Application
独立的分隔符

自定义单独的分隔符。

expand codeexpand code
TypeScript
JavaScript
import { Breadcrumb } from 'mogud';
import React from 'react';

const App: React.FC = () => (
  <Breadcrumb
    separator=""
    items={[
      {
        title: 'Location',
      },
      {
        type: 'separator',
        separator: ':',
      },
      {
        href: '',
        title: 'Application Center',
      },
      {
        type: 'separator',
      },
      {
        href: '',
        title: 'Application List',
      },
      {
        type: 'separator',
      },
      {
        title: 'An Application',
      },
    ]}
  />
);

export default App;

API

Breadcrumb

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

ItemType

type ItemType = RouteItemType | 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(item, params, items, paths) {
const last = items.indexOf(item) === items.length - 1;
return last ? <span>{item.title}</span> : <Link to={paths.join('/')}>{item.title}</Link>;
}
return <Breadcrumb itemRender={itemRender} items={items} />;

Design Token

Global Token