Despite checking all the answers already posted on stack overflow I coudn't find the solution for my case, so I'll post it.
I'm using {Router} from 'react-router (v6) to be able to use a custom history object to be able to navigate in my redux actions.
Here are my files:
index.tsx
import { Router } from 'react-router';
import myHistory from './utils/history';
ReactDOM.render(
<Provider store={store}>
<Router navigator={myHistory} location={myHistory.location}>
<App />
</Router>
</Provider>,
document.getElementById('root')
);
App.tsx
import MainNavigation from './components/navigations/MainNavigation';
import Routes from './routes/Routes';
const App = () => {
return (
<>
<MainNavigation />
<Routes />
</>
);
};
export default App;
MainNavigation.tsx
import { Link } from 'react-router-dom';
const MainNavigation = () => {
return (
<nav className='navigation'>
<ul>
<li>
<Link to='/'>Home</Link>
</li>
<li>
<Link to='/contact'>Contact</Link>
</li>
<li>
<Link to='/about'>A propos</Link>
</li>
<li>
<Link to='/user-profile'>Votre compte</Link>
</li>
</ul>
</nav>
);
};
export default MainNavigation;
Route.ts
import { Route, Routes as Routing } from 'react-router';
const Routes = () => {
return (
<Routing>
<Route path='/' element={<Home />} />
<Route path='/about' element={<About />} />
<Route path='/contact' element={<ContactForm />} />
<Route path='/user-profile' element={<UserAccount />} />
{/* <Route path='*' component={Error404} /> */}
{/* <Navigate to='/' /> */}
</Routing>
);
};
export default Routes;
The issue: when I click on one of the link the url changes to the corresponding path but the component doesn't render. I have to refresh the page to actually make it appear. I really don't know what's going on.
Thank you.