来源于:https://blog.csdn.net/weixin_45264424/article/details/120000759
使用 useHistory:
import { Route, useHistory } from "react-router-dom";
function App() {
const goDetail = (testPlanNumber) => {
history.push(`/app/testing/plan/${testPlanNumber}`)
}
}
return (
<div>
<Button onClick={() => goDetail(record.testPlanNumber)}>详情</Button>
</div> );
}
export default App;
使用withRouter:
import { Route, withRouter} from "react-router-dom";
function App(props) {
const goDetail = (testPlanNumber) => {
props.history.push(`/app/testing/plan/${testPlanNumber}`)
}
}
return (
<div>
<Button onClick={() => goDetail(record.testPlanNumber)}>详情</Button>
</div> );
}
export default App;
网友评论