Programmatically navigate using react router

后端 未结 30 2288
無奈伤痛
無奈伤痛 2020-11-21 05:18

With react-router I can use the Link element to create links which are natively handled by react router.

I see internally it calls t

30条回答
  •  臣服心动
    2020-11-21 05:49

    In react router v4. I follow this two way to route programmatically.

    1. this.props.history.push("/something/something")
    2. this.props.history.replace("/something/something")
    

    Number two

    Replaces the current entry on the history stack

    To get history in props you may have to wrap your component with

    withRouter

提交回复
热议问题