Ability to unsubscribe from hashHistory.listen()
See original GitHub issueWhile trying to find the best solution for creating my own breadcrumb, I found it difficult to get route information into a sibling component in my case a navigation bar.
As of right now i’m using the hashHistory.listen()
method and splitting the response using event.pathname.split("/")
. This method works but since i’m using an event listener i receive an error if i navigate to a new route that doesn’t contain my component. This the the expected behavior which leads me to think that there should be an unlisten()
method to hashHistory.
Another plus would be to have both parent and child routes listed in the hashHistory.listen()
response. This would help tremendously in know the exact components used to render parameters.
Issue Analytics
- State:
- Created 7 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Ability to unsubscribe from hashHistory.listen() #3792 - GitHub
listen() is an "unlisten" function you can call. But you're provided the location on your route component. Pass that down via props to...
Read more >Prevent react-router history.push from reloading current route
I'm taking my first steps with react-router . I'm currently using the hashHistory for development purposes and I'm performing 'manual' navigation. That is...
Read more >Different History modes - Vue Router
The hash history mode is created with createWebHashHistory() : ... but note there will be no history, meaning you won't be able to...
Read more >Lock API Reference - Auth0
Lock has many methods, features, and configurable options. This reference is designed to direct you to the ones that you need, and discuss...
Read more >历史 | React 和 Webpack 小书
React Router is built on history. In a nutshell, a history knows how to listen to the browser's address bar for changes and...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
First, the return from
history.listen()
is an “unlisten” function you can call.But you’re provided the location on your route component. Pass that down via props to your breadcrumb component if you need it deeper in the tree.
After further research i finally understand what you were both trying to convey. I couldn’t wrap my mind around how a parent component would know a child component’s route without re-rendering. but for anybody looking to accomplish the same task you can get all active routes in a child component by passing
routes={this.props.routes}
to the component and access the current route object usingroutes[routes.length -1]
Thank you both. React router is awesome.