I want to access the current location path (like /home) without the history keys for some comparison logic.
How can i access it from the hashHistory in react router 2.
Also, how can i access the previous path?
You can obtain the current pathname from the location
prop of your route component.
Access location from this.props.location of your Route component. If you'd like to get it deeper in the tree, you can use whatever conventions your app has for getting props from high down low. One option is to provide it on context yourself:
// v2.0.x const RouteComponent = React.createClass({
childContextTypes: { location: React.PropTypes.object },getChildContext() { return { location: this.props.location } } })
Have a look here.
To get the current path, you can just use location.pathname
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With