2

I need to know how react-router-dom persists state object, for example i have a route like this: 'http://localhost:3000/somepath/123', if i open this route on the new browser tab, state object is obviously undefined, if i redirected from somewhere to this route then state is an object from application state, this is completely normal... but the thing is, when i redirected from different route and i refresh the page several times the state is again an object, how react persist state even if i refresh the page?

<Link
  to={{
    pathname: '/somepath/:someid',
    state: state.obj[someid]
  }}
>
 Link to somepath
</Link>
Bakshi
  • 110
  • 8
  • Possible duplicate of [How to pass params with history.push/Link/Redirect in react-router v4?](https://stackoverflow.com/questions/44121069/how-to-pass-params-with-history-push-link-redirect-in-react-router-v4) – ravibagul91 Aug 17 '19 at 21:50

1 Answers1

3

React-router-dom doesn't persist state. Browser does.
React router uses history API to push & pop states.

The behaviour you describe is how history.state works.
So after you refresh, browser keeps the history state.
Check History API

George Sofianos
  • 1,141
  • 1
  • 13
  • 26