0

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

Bryan Campbell
  • 285
  • 3
  • 9
  • What happens if we also mark the bottom export default as an observer? I am using mobx as well, though I can't say I've ever faced those issues. Normally if I want to make some sort of function that affects a variable in my state I prefix it with @action – SomeStudent Jun 21 '20 at 19:08

1 Answers1

2

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.

Danila
  • 15,606
  • 2
  • 35
  • 67