How to push to History in React Router v4?

后端 未结 21 2273
不思量自难忘°
不思量自难忘° 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条回答
  •  猫巷女王i
    2020-11-22 01:17

    This is how I did it:

    import React, {Component} from 'react';
    
    export default class Link extends Component {
        constructor(props) {
            super(props);
            this.onLogout = this.onLogout.bind(this);
        }
        onLogout() {
            this.props.history.push('/');
        }
        render() {
            return (
                

    Your Links

    ); } }

    Use this.props.history.push('/cart'); to redirect to cart page it will be saved in history object.

    Enjoy, Michael.

提交回复
热议问题