Better defaults!
See original GitHub issueLove your work here @icd2k3! Found it reading through https://github.com/ReactTraining/react-router/issues/4556.
I think we can do something to improve the defaults and avoid configuration for most cases. Here’s how:
Instead of requiring this object every time you’re going to use the HOC
const routes = [
{ path: '/', breadcrumb: 'Home' },
{ path: '/users', breadcrumb: 'Users' },
{ path: '/users/:userId', breadcrumb: UserBreadcrumb },
{ path: '/something-else', breadcrumb: ':)' },
];
we could have, by default, a text transformation over the chunks of the URL.
users
> Users
something-else
> Something Else
something-with-even-more-hyphens
> Something with even more hyphens
This would be an incremental upgrade: you can still pass the routes
param to the HOC to set custom breadcrumbs on a per-route basis.
To achieve this string-humanization-by-default I suggest using https://github.com/sindresorhus/humanize-string.
Let me know if you think this is a good idea, I’m more than willing to submit a PR if that’s the case.
Thanks for your work.
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (4 by maintainers)
FYI this is now included as part of
2.0.0
along with some other core changes listed hereHey @nachoaIvarez, thanks for the suggestion! At initial glance I think it sounds like a good improvement idea!
One concern: Users might not want to render a breadcrumb from some route segments. In this case we’d need some kind of opt-out option if each segment automatically returns a default string.
I should have some time within the next couple weeks to try this idea on my end. In the meantime I’d be happy to take a look at a PR as well!