Is it possible to get the previous number of paths and the path values from ReactRouter.browserHistory?
To detect previous path in React Router, we can set the state property to an object with the location. pathname as the value. <Link to={{ pathname: "/nextpath", state: { prevPath: location.
To go back to previous route in react-router-dom v6 First of all, you need to import useNavigate from react-router-dom and then you can use navigate(-1) to go back to the previous version If You want to Go 2 pages back then probably you have to use navigate(-2).
React Router has a useHistory hook that provides a history interface that we can easily use for routing. Add buttons to these pages as shown below to add routing with the History API. The snippet above uses the goBack() method to mimic the back button in the browser and the push() method to move to a new route.
Actually you can't.
But you can try storing a list in browserHistory state and pushing new path in it when you redirect.
let history = this.props.location.state.history;
history.push(this.props.location.pathname)
browserHistory.push({
pathname: '/yourpath',
state: { history: history }
})
in this way you should find all your history in this.props.location.state.history
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