history:push()로 페이지 이동 설정
1. <button> 요소 사용
<Link>를 사용하지 않고<button>을 사용해서 페이지 이동 설정을 하기 위해서는 history 객체의 push() 메서드를 사용할 수 있다.
import { useHistory } from "react-router-dom";
function HomeButton() {
let history = useHistory();
function handleClick() {
history.push("/home");
}
return (
<button type="button" onClick={handleClick}>
Go home
</button>
);
}2. <a> 요소 사용
<a
href="#go-to-movies"
onClick={(e) => {
e.preventDefault()
history.push('/movies')
}}
>Last updated
Was this helpful?