Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Pass the `router` instance down to Route children; React 0.13.3, React Router 1.0.0beta-4, ES2015, ES6
import React from 'react';
// Top-level Route component receives the router in context and passes it onto each child's props
export default class AppView extends React.Component {
render() {
return (
<div className="container">
{
// Add `props.router` to each route component
React.Children.map(this.props.children, c => {
return React.cloneElement(c, { ...c.props, router: this.context.router });
})
}
</div>
);
}
}
AppView.contextTypes = {
router: React.PropTypes.object.isRequired
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.