【问题标题】:How to make highchart points redirect to another component with value in React?如何使高图点重定向到 React 中具有值的另一个组件?
【发布时间】:2019-05-11 16:13:52
【问题描述】:

在 highcharts 中,通过单击数据点,我需要通过在 react 中传递点值来重定向到另一个页面。 我正在使用到达/路由器。有没有什么可以让我们像反应/路由器链接这样的点。


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

【问题讨论】:

    标签: reactjs highcharts react-highcharts reach-router


    【解决方案1】:

    您需要访问组件并使用历史对象将新路由推送到组件的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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-16
      • 2018-01-13
      • 2022-01-24
      • 1970-01-01
      • 2022-01-24
      • 2020-06-14
      • 2021-12-09
      • 2016-07-07
      相关资源
      最近更新 更多