Last active
August 29, 2015 14:25
-
-
Save tmbtech/a53c239925f9caac2dff to your computer and use it in GitHub Desktop.
Get props from route
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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