npm install history@5 react-router-dom@6
import { useNavigate } from 'react-router';
let navigate = useNavigate();
navigate('/home')
function Redirect() {
let navigate = useNavigate();
function handleClick() {
navigate('/home')
}
return (
<div>
<button onClick={handleClick}>go home</button>
</div>
);
}
function Redirect() {
let navigate = useNavigate();
function handleClick() {
navigate(-1)
}
return (
<div>
<button onClick={handleClick}>go home</button>
</div>
);
}
function Redirect() {
let navigate = useNavigate();
function handleClick() {
navigate(1)
}
return (
<div>
<button onClick={handleClick}>go home</button>
</div>
);
해당 내용은 다음 자료를 참고했습니다.
https://intrepidgeeks.com/tutorial/usenavigate-tutorial