React Router Redirect Conditional

后端 未结 3 843
生来不讨喜
生来不讨喜 2021-02-10 19:10

I\'m trying to make a button that only redirects the user to a new page after validation is completed correctly.

Is there a way of doing something like this? How to I g

3条回答
  •  面向向阳花
    2021-02-10 19:39

    As discussed you should have access to the history object via this.props.history as described here.

    If you look into the push function this will redirect you to any route you need. For example:

    // Use push, replace, and go to navigate around.
    this.props.history.push('/home', { some: 'state' })
    

    https://reacttraining.com/react-router/web/api/history

提交回复
热议问题