1

In my React app, I do conditional logic on a route Component’s initialization/rendering based on where the user came from. If he came from Page A, then the Link to the page holds state data that is read from this.props.location.state when the route is rendered. But on refresh, I need the page to “forget” where the user came from (or more specifically, clear location.state).

Unfortunately, Reach Router doesn’t use history as a dependency, so it seems solutions like these which advocate for history.update() won’t work.

actinidia
  • 236
  • 3
  • 17

1 Answers1

0

To start, the history.update() documentation you were looking at is for react-router, not reach-router (they are very similar but are NOT the same and looking at the wrong docs is only going to cause you headaches).

The next issue that you might be running into is that you need to figure out what part of the location.state you need to change. This would depend on what you set in the state when the user navigates to the page. By default, the reach-router state only contains a key, the state that is used to conditionally render is a value set by you. So what you need to remove is the location.state.value (value being whatever you set) by setting the value to null or false which should stop the conditional rendering.

Jryke
  • 138
  • 7