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