Ad

Where Did They Get The Router Context

- 1 answer

On the example folder of react-router where did they get the router context on Login.js. I'm very confused on this on. For reference, here's the link for the Login.js file.

I didn't see any variable declartion on router.

Ad

Answer

RouterContext has childContextTyperouter

https://github.com/rackt/react-router/blob/master/modules/RouterContext.js#L36

childContextTypes: {
    history: object,
    location: object.isRequired,
    router: object.isRequired
},

And login.js has this.

contextTypes: {
    router: React.PropTypes.object
},

This is based on Context

Ad
source: stackoverflow.com
Ad