Im using mobx to hold my login state. After logging in, navigating to a new route with react router forces my store to reset and logs me out. What am I doing wrong?
https://codesandbox.io/s/staging-cache-k7c8c?file=/src/App.js
Im using mobx to hold my login state. After logging in, navigating to a new route with react router forces my store to reset and logs me out. What am I doing wrong?
https://codesandbox.io/s/staging-cache-k7c8c?file=/src/App.js
You are using Nav.Link
from react-bootstrap
, but they act like regular a
link tags, they reload whole page when clicked so everything gets cleaned up, reset.
What you need to do is use Link
component from react-router-dom
like that <Link to="/">Home</Nav.Link>
(make sure to rename href
prop to to
). Then page won't be reloaded, instead browser history would be utilized.