Is it possible to access the current route component using React Router

For example, I have routes like:

<Route path="about" component={AboutPage} /> <Route path="status" component={StatusPage} /> 

Suppose the current route is '#/about' . I need something like routerInstance.currentComponent to return an instance of the AboutPage component.

Does React Router have a way to do this?

ps. I understand that accessing component instances from the outside is not a real way to do something, but I need it nonetheless.

+6
source share
1 answer

not sure if the intermediary agent is already providing it, theres the old GitHub discussing undocumented api's here , but you can install it yourself along the Route.

 //AboutPage componentDidMount() { global.currentComponent = this } //StatusPage componentDidMount() { global.currentComponent = this } 
+2
source

All Articles