React Router work on reload, but not when clicking on a link

I would go through your components and make sure you have only one <Router> ... </Router>. Also — make sure you have a <Router>...</Router> There may be cases when you’d use more than one, but if you accidentally have nested routers (because you were hacking quickly and forgot to remove one when you were moving it around to all kinds of places 😉 – it could cause an issue.

I would try

import {
  BrowserRouter as Router,
}  from 'react-router-dom'

// Other Imports

...

return (
  <Router>
    <div className="index">
      <Nav /> <!-- In this component you have <Links> -->
      <div className="container">
        <Routes />
      </div>
    </div>
  </Router>
);

In your top most component (App.js).

Leave a Comment