2015-07-19 162 views
1

此鏈接介紹如何在組件上設置了ref和從父調用它的函數揭露子組件功能於母公司與REF react-router和我想要引用的組件是一個路由,父節點是根組件?使用反應路由器

回答

1

這工作: 給<RouteHandler/>一個引用,就像這樣:<RouteHandler ref="routerHandler"/>

然後調用這樣的: this.refs.routerHandler.refs.__routeHandler__.someFunctionOnActiveRoutesHandler()

+0

任何想法的反應路由器2.X相當於這是什麼? –

+1

React路由器2.0爲您提供this.props.children。使用這種方法來獲得一個ref:http://stackoverflow.com/questions/29568721/getting-dom-node-from-react-child-element,並且這種方法調用一個函數:https://facebook.github。 IO /反應/提示/暴露組分-functions.html。請記住這是一種反模式。 – user2827377