For example I have routes like:
<Route path="about" component={AboutPage} />
<Route path="status" component={StatusPage} />
Lets assume that the current route is '#/about'
. I need something like routerInstance.currentComponent
to return AboutPage
component instance.
Does React Router has a method to do it?
ps. I understand that accessing component instances from the outside is not the React Way to do things, but nevertheless I need it.
not sure if react-router already exposes it, theres an old GitHub discussing undocumented api's, here but you could set it yourself per Route.
//AboutPage
componentDidMount() {
global.currentComponent = this
}
//StatusPage
componentDidMount() {
global.currentComponent = this
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With