Can anyone please tell me how I can go back to the previous page rather than a specific route?
When using this code:
var BackButton = React.createCla
useNavigate Hook is the recommended way to go back now:
import { useNavigate } from 'react-router-dom';
function App() {
const navigate = useNavigate();
return (
<>
>
);
}
Codesandbox sample
Go back/forward multiple history stack entries:
Go to specific route:
navigate("users") // go to users route, like history.push
navigate("users", { replace: true }) // go to users route, like history.replace
navigate("users", { state }) // go to users route, pass some state in
useNavigate replaces useHistory to support upcoming React Suspense/Concurrent mode better.