首页 文章

使用react-router将子组件函数公开给使用ref的父组件

提问于
浏览
1

此链接描述了如何在组件上设置ref并从父级调用其函数:https://facebook.github.io/react/tips/expose-component-functions.html

当我使用react-router并且我想要ref的组件是路由而父组件是根组件时,我如何实现这一点?

1 回答

  • 1

    这样做:给 <RouteHandler/> 一个参考,像这样: <RouteHandler ref="routerHandler"/>

    然后像这样打电话: this.refs.routerHandler.refs.__routeHandler__.someFunctionOnActiveRoutesHandler()

相关问题