useHistory 鈎子允許您訪問可能用於導航的歷史實例。
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> ); }
更多跳轉方式可參考:https://reacttraining.com/react-router/web/api/Hooks