1

So I am using React Router v3. Say I go from route A to route B. Then pressing the back button I can go back to A but how do I disable going to B again pressing the forward button. Going to B via a Link in the application or programmatically is fine. But I don't want the application to be able to go forward using the browser's forward button.

I assume it will be something like removing the last element of the route stack but I can't seem to get my head around it. Any help will be appreciated.

mrinalmech
  • 2,065
  • 1
  • 20
  • 18
  • Possible duplicate of [react-router: how to get the previous route in onEnter handler?](https://stackoverflow.com/questions/36654475/react-router-how-to-get-the-previous-route-in-onenter-handler) See if that helps you. – Chris May 22 '17 at 21:54

1 Answers1

0

You can handle this situation with history.replaceState() method (or a similar dispatcher, if use react-router-redux). The most problem I see is to find a moment when user clicks 'go back' button.

Anyway, in my opinion, if you are forced to look for such workarounds, there is probably something wrong in how your application works. Routes should be able to be accessed from anyplace. If user needs to be authorized or something like this, then you should write some guard method inside that route and redirect user (if conditions were not met) to other route.

GProst
  • 9,229
  • 3
  • 25
  • 47