0.1.0 • Published 6 years ago

@methodexists/dva-ant-breadcrumbs v0.1.0

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

dva-ant-breadcrumbs

Antd’s Breadcrumb component connected to dva router.

Installation

npm i @methodexists/dva-ant-breadcrumbs

Usage

Put <Breadcrumbs /> component inside render method of your route component:

const UsersPage = ({ routes, params }) => (
  <div>
    <Breadcrumbs routes={routes} params={params} />
  </div>
);

Zero configuraton

The component will analyze route’s path and will try to guess the best title for each bread crumb.

URLPathGuessed titles
/userProfileuserProfile"User Profile"
/usersusers"Users"
/users/ilyausers/:username"Users" / "Ilya"
/users/9jerbusers/:id"Users" / "9jerb" (here you’ll need customization)

Custom static title

Add title prop to a route and it will be used for bread crumb’s title.

<Route path="userProfile" title="My Profile" ... />

Custom dynamic title

Add getTitle prop to calculate bread crumb’s title basing on params from the router and state.

<Route path=":id" getTitle={(params, state) => state.users[params.id].name} />

Fallbacks

If getTitle() prop is undefined or returns undefined then use title.
If title is undefined then guess title from path.

API

Routes API

PropTypeDescription
* pathstringRoute’s path. If undefined, the route will be skipped. Could be param name like :username
getTitle(params, state) => stringFunction to generate route’s title basing on params prop from router and current state
titlestringText to use for route’s title

<Breadcrumbs /> API

PropDescription
* routesroutes prop provided by router into root route component
* paramsparams prop provided by router into root route component

* required

Also supports Ant Design Breadcrumb component props: prefixCls, separator, itemRender, style, className.

Contributing

See CONTRIBUTING.md for how to develop a component.

0.1.0

6 years ago

0.0.1

7 years ago