函数式组件(无状态)的路由跳转

2022-03-09  本文已影响0人  懒懒猫

来源于: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;
上一篇 下一篇

猜你喜欢

热点阅读