如何使高图点重定向到React中具有值的另一个组件?

时间:2019-05-11 16:13:52

标签: reactjs highcharts react-highcharts reach-router

在高图中,通过单击数据点,我需要通过在react中传递点值来重定向到另一页。 我正在使用覆盖面/路由器。有什么可以像React / Router Link这样的观点。


 plotOptions :{
                series: {
                    cursor: 'pointer',
                    point: {
                        events: {
                            click: function () {
                                console.log(this);
                                // want to redirect to other component like Link in Reach/router.
                            }
                        }
                    }
                }
            }

1 个答案:

答案 0 :(得分:0)

您需要访问组件并使用历史对象将新路由推入组件的props.history

options: {
    series: [{
        data: [1, 2, 3],
        point: {
            events: {
                click: function() {
                    this.props.history.push("/");
                }.bind(this)
            }
        }
    }]
}

实时演示: https://codesandbox.io/s/848vly9pn8

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