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

When returning null an empty breadcrumb is returned instead #78

Open
InfiAest opened this issue Apr 18, 2023 · 1 comment
Open

When returning null an empty breadcrumb is returned instead #78

InfiAest opened this issue Apr 18, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@InfiAest
Copy link

Hi there 👋

I have stumbled across a problem where if you try to return null to the breadcrumb it renders an empty crumb instead of nothing.
Please see this codesandbox for an extremely basic example of the problem https://codesandbox.io/s/react-router-breadcrumbs-bug-infiaest-37wkbt?file=/index.tsx

As you can see in the codesandbox above I would like the breadcrumbs to display as Home / All Events when on the page with the pathname "/events" and then as Home / Event Name when on the child page with the pathname "/events/1".

I have used the function location.pathname === "/events" ? <span>All Events</span> : null which should return the desired breadcrumb. However returning null like this results in the breadcrumb containing an empty crumb like this: Home / / Event Name

Any help/fixes would be greatly appreciated! 🤔

@icd2k3 icd2k3 added the enhancement New feature or request label Apr 20, 2023
@icd2k3
Copy link
Owner

icd2k3 commented Apr 20, 2023

ok, so the problem here is that when the breadcrumbs are mapped over it sees breadcrumb as a function (not null) because it is dynamically rendered...

As an enhancement to this repo, it's probably possible to check if the breadcrumb component is null here in the src and return a flat null instead of the whole component. I'll have to look into this a bit more for

In the meantime, the only workaround I can think of would be to check the location object in the breadcrumb.map and conditionally render it - or use a unique path like events/all vs events/:id to make use of priority ordering. It also might be worth trying the official RR breadcrumb docs to see if it might provide more flexibility.

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

No branches or pull requests

2 participants