// 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
<Link to={document.URL.indexOf("http://localhost:3000/contact") - 1 } className='text-black mx-6 flex justify-self-center my-1 font-lato relative'>Go back</Link>
// If you have the props from react router
history.goBack()
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>