How do I manage history in my react project using react-router-dom v6
? Currently what is happening is that when the user clicks on the browsers' back button it takes him to the default browsers' page instead of the previous page he visited on the website.
Here's the code
index.tsx
ReactDOM.render(
<React.StrictMode>
<BrowserRouter>
<App />
</BrowserRouter>
</React.StrictMode>,
document.getElementById("root")
);
App.tsx
<ErrorBoundary>
<Router />
</ErrorBoundary>
Router.tsx
const Router: React.FC = (): JSX.Element => {
return (
<Suspense fallback={<Loader loadingText="Loading..." />}>
<Routes>
<Route path="" element={<RouteGuard />}>
<Route path="" element={<Home />} />
</Route>
<Route path="*" element={<Error404 />} />
</Routes>
</Suspense>
);
};