Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Advanced usage with custom items #56

Closed
anteburazer opened this issue Jun 15, 2021 · 2 comments
Closed

Advanced usage with custom items #56

anteburazer opened this issue Jun 15, 2021 · 2 comments

Comments

@anteburazer
Copy link

Hi

I have the Project page with route/project/:projectId and Task page with route /task/:taskId. Project page contains the list of tasks and clicking on it redirects the user to the Task page.
Those two pages have independent routes, defined on the top level. When displaying Task page I want to have a breadcrumb project_name -> task_name which requires some custom logic because the library will not display the whole chain since Task route is not nested inside the Project route.

How I can achieve that?

@oklas
Copy link
Owner

oklas commented Jun 15, 2021

Hi

It need to mention that the length of url (filed to) is used to sort crumbs when breadcrumbs is generated.

So you have several ways:

  • correct routes to match object relation:
<Route path='/project/:projectId' component={Project} />
<Route path='/project/:projectId/task/:taskId' component={Task} />
...
<BreadcrumbsItem to=`/project/123` children={projectName} />
<BreadcrumbsItem to=`/project/123/task/123` children={taskName} />
  • use special filed for sorting and specify compare function at breadcrumbs instance:
<Breadcrumbs compare={(a,b)=>a.weight-b.weight} />
...
<BreadcrumbsItem weight=0 to=`/project/123` children={projectName} />
<BreadcrumbsItem weight=1 to=`/task/123` children={taskName} />
  • add some unsignificant text to increate length of url to correct sorting (see remark about sorting above):
<BreadcrumbsItem to=`/project/123` children={projectName} />
<BreadcrumbsItem to=`/task/123#something` children={taskName} />

@anteburazer
Copy link
Author

Thank you @oklas. Multiple BreadcrumbsItem with weight fixed the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants