usehistory
import { useNavigate } from 'react-router-dom';
const navigate = useNavigate();
navigate('/home');
Motionless Mole
import { useNavigate } from 'react-router-dom';
const navigate = useNavigate();
navigate('/home');
import { useHistory } from 'react-router-dom';
function Home() {
const history = useHistory();
return <button onClick={() => history.push('/profile')}>Profile</button>;
}
import { useHistory } from "react-router-dom"; // DEPRECATED
// It is now
import { useNavigate } from "react-router-dom"; // As at March 3, 2022
// useHistory() has been changed in v6, so instead use useNavigate()
check out the source link