美文网首页
函数式组件(无状态)的路由跳转

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

作者: 懒懒猫 | 来源:发表于2022-03-09 17:38 被阅读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;
    

    相关文章

      网友评论

          本文标题:函数式组件(无状态)的路由跳转

          本文链接:https://www.haomeiwen.com/subject/nmddrrtx.html