Skip to content

Instantly share code, notes, and snippets.

@tmbtech
Last active August 29, 2015 14:25
Show Gist options
  • Save tmbtech/a53c239925f9caac2dff to your computer and use it in GitHub Desktop.
Save tmbtech/a53c239925f9caac2dff to your computer and use it in GitHub Desktop.
Get props from route
class Index extends React.Component {
componentDidMount() {
const {branch: branches, location} = this.props;
const component = branches.filter(branch => branch.childRoutes)
.map(branch => branch.childRoutes.find(childRoute => childRoute.path === location.pathname))
.reduce(element => element);
console.log(component.foo); // LOG: bar
}
render() {
return (
<div className="index">
<h1>Index Page</h1>
</div>
);
}
}
export default Index;
/*
<Route path={route.for("Index")} foo={"bar"} component={Index} />
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment