How to push to History in React Router v4?

后端 未结 21 2356
不思量自难忘°
不思量自难忘° 2020-11-22 00:27

In the current version of React Router (v3) I can accept a server response and use browserHistory.push to go to the appropriate response page. However, this isn

21条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2020-11-22 01:20

    this.context.history.push will not work.

    I managed to get push working like this:

    static contextTypes = {
        router: PropTypes.object
    }
    
    handleSubmit(e) {
        e.preventDefault();
    
        if (this.props.auth.success) {
            this.context.router.history.push("/some/Path")
        }
    
    }
    

提交回复
热议问题