关于如何在Router V6的函数式编程和钩子中导航的文档很多。例如:
https://reactrouter.com/docs/en/v6/getting-started/tutorial#navigating-programmatically
import { useNavigate } from "react-router-dom";
let navigate = useNavigate();
navigate("/some/url");但是,如果扩展React.Component,则没有任何文档说明如何导航。如何从React.component以编程方式进行导航?
发布于 2022-06-05 16:32:35
这是我唯一能找到的解决办法
import * as React from "react";
class Dashboard extends React.Component {
constructor(props) {
super(props);
this.goTo = this.goTo.bind(this);
}
goTo() {
window.location.href = "/about";
}
render() {
return (
<div>
<h1>Dashbaord</h1>
<button onClick={this.goTo}>Go Home</button>
</div>
);
}
}
export default Dashboard;
https://stackoverflow.com/questions/72504683
复制相似问题