我有一个反应应用程序。在一个组件中,我有一个来自 react-router 的 Link comp。当我点击链接时,路由器会触发推送和弹出操作?这是正常的吗?这样我不知道如何解决问题。我有这样的路由设置:example/:param 当我在这条路径上时,我怎样才能正确地听取 param 段的变化?

码:

class Example extends Component {
    fetch(param) {
        // ajax stuff
    }
    componentWillMount() {
        this.fetch(this.props.param);
    }

    componentWillReceiveProps(nextProps) {
        this.fetch(nextProps.param);
    }

    render() {
        // render stuff
    }
}

const stateToProps = (state, ownProps) => {
    return {
        param: ownProps.params.param,
    };
};

export default connect(stateToProps, {})(Profile);

这种方式 componentWillReceiveProps 运行两次 beacuse 路由器 fires push 和 pop 动作。

任何 help/advice,Akos 的 Thx