Comments (7)
Hey @Sven65,
Currently this isn't supported, but it probably should be! I'll look into implementing this in the near future...
from react-router-breadcrumbs-hoc.
This turned out to be easier than I originally thought (pretty sure this PR above will cover it... at least all the tests are passing). If you have time to check it out, an extra set of 👀never hurts!
from react-router-breadcrumbs-hoc.
I'll check it out tomorrow, thanks!
from react-router-breadcrumbs-hoc.
Alright, I had a look at it and I found some issues.
Using the demo shown here, I get these breadcrumbs:
Route | Breadcrumb |
---|---|
/applications/:id | Home / Applications / Edit Application |
/applications | Home / 404 |
/admin | Home / 404 |
/admin/apps | Home / Admin / 404 |
/admin/apps/:id | Home / Admin / Apps / 404 |
/privacy | Home / 404 |
/terms | Home / 404 |
import withBreadcrumbs from 'react-router-breadcrumbs-hoc'
import React from 'react'
import { Link } from 'react-router-dom'
const breadcrumbRoutes = [
{ path: '/applications/:id', breadcrumb: 'Edit Application' },
{ path: '/admin/apps/:id', breadcrumb: 'Edit Application' },
{ path: '/privacy', breadcrumb: 'Privacy Policy' },
{ path: '/terms', breadcrumb: 'Terms of Service' },
]
const BreadcrumbDemo = ({
breadcrumbs,
}) => (
<div>
{
breadcrumbs.map(crumb => (
<span key={crumb.key}>
<Link to={crumb.props.match.url}>
{ crumb.props.children }
</Link>
</span>
))
}
</div>
)
export default withBreadcrumbs(breadcrumbRoutes, {
routeNotFoundBreadcrumb: '404',
})(BreadcrumbDemo)
As for my routes, these are the ones I have.
<Switch>
<Route path="/" exact component={Home} />
<Route path="/oauth" component={OAuth} />
<Route path="/applications" component={Dash} />
<Route path="/applications/:id" exact component={Dash} />
<Route path="/docs" component={Docs} />
<Route path="(/privacy|/terms)" exact component={Legal} />
<Route path="/admin(|/|/apps|/users)" exact component={Admin} />
<Route path="/admin/apps/:id" exact component={Admin} />
<Route component={Page404} />
</Switch>
from react-router-breadcrumbs-hoc.
Thanks for having a look!
Arg, yea, seems like this is a bit more complex than I originally thought... Back to the drawing board! In the meantime, there might be some way to leverage withRouter (not sure if it knows about 404 routes or not 🤔).
from react-router-breadcrumbs-hoc.
Alright, did some more investigating... The main problem is this HOC is unaware of the routes you might have set upstream, so determining which routes are 404 doesn't seem possible from the HOC AFAIK (if someone does know of a way, please let me know!)
This is a bit hacky, but if I were to solve this use-case without a change to this HOC I would probably do it through a css class:
Breadcrumbs.jsx
<div>
{
breadcrumbs.map(crumb => (
<span key={crumb.key}>
<Link to={crumb.props.match.url}>
{ crumb.props.children }
</Link>
</span>
))
}
<span className="route-not-found-breadcrumb">404</span>
</div>
Page404.jsx
// ...
componentDidMount() {
body.classList.add('is-404');
}
componentWillUnmount() {
body.classList.remove('is-404');
}
// ...
Breadcrumbs.css
.route-not-found-breadcrumb { display: none; }
body.is-404 .route-not-found-breadcrumb { display: inline-block; }
If anyone has ideas about how to support this functionality in this HOC, I'm all ears! Again, the main issue is that I don't see a good way of checking which routes the user has defined upstream.
from react-router-breadcrumbs-hoc.
Closing this because it is over a year old, and has a workaround documented.
from react-router-breadcrumbs-hoc.
Related Issues (20)
- Translated breadcrumbs (delaying routes init) HOT 1
- dassad
- Unnecessary peer dependency on react-router-dom HOT 4
- "//" produces double matches HOT 1
- Unable to pass additional props. HOT 3
- define breadcrumb‘s description HOT 2
- Disabling default generated breadcrumbs by passing breadcrumb: null raises an error HOT 2
- Property 'match' does not exist on type 'ReactNode' HOT 1
- What to use instead of InjectedProps HOT 3
- Replacing react-router with react-router-dom HOT 2
- Fixed
- Suppress autmatically added Home Breadcrumb HOT 2
- Issue with excludePaths not being consistent with breadcrumbs: null HOT 6
- Question about type definition HOT 3
- typescript definition mistake HOT 1
- How do I add in between crumbs ? HOT 2
- Question: Is there a way to not export the current page in breadcrumbs HOT 2
- Question: breadcrumbs propTypes HOT 1
- How to remove "-" from titles HOT 3
- react-router v6 HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-router-breadcrumbs-hoc.