简体   繁体   English

使用react-router将带有ref的子组件功能公开给父组件

[英]Expose child component functions to parent with ref using react-router

This link describes how you can set a ref on a component and call its functions from a parent: https://facebook.github.io/react/tips/expose-component-functions.html 此链接描述了如何在组件上设置引用并从父对象调用其函数: https : //facebook.github.io/react/tips/expose-component-functions.html

How do i achieve this when i'm using react-router and the component I want to ref is a route and the parent is the root component? 当我使用react-router并且我要引用的组件是路由而父级是根组件时,如何实现此目的?

This works: Give <RouteHandler/> a ref, like this: <RouteHandler ref="routerHandler"/> 这有效:给<RouteHandler/>引用,例如: <RouteHandler ref="routerHandler"/>

Then call like this: this.refs.routerHandler.refs.__routeHandler__.someFunctionOnActiveRoutesHandler() 然后像这样调用: this.refs.routerHandler.refs.__routeHandler__.someFunctionOnActiveRoutesHandler()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM