// To get back to previous url adress:
import { useNavigate } from "react-router-dom";
const MyButton = () => {
const navigate = useNavigate();
return (
<button
onClick={() => {
navigate(-1);
}}
>
Click me to go back!
</button>
);
};
export default MyButton
// If you have the props from react router
history.goBack()
// Step 1:
import { useNavigate } from "react-router-dom";
// Step 2:
const navigate = useNavigate();
// step 3:
<button onClick={() => navigate(-1)}> Back </button>