// 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
const history = useHistory()
const goBack = () => {
history.goBack()
}
return (
<button type="button" onClick={goBack}>
Go back
</button>
);
// Step 1:
import { useNavigate } from "react-router-dom";
// Step 2:
const navigate = useNavigate();
// step 3:
<button onClick={() => navigate(-1)}> Back </button>