Created
March 29, 2017 05:37
-
-
Save soundyogi/ee72a05c0d704a3bfb3cbbe82fcd3cee to your computer and use it in GitHub Desktop.
react router v4 nesting
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
// wrap <Route> and use this everywhere instead | |
function RouteNest(props){ return ( | |
<Route exact={props.exact} path={props.path} render={ p => <props.component {...p} children={props.children}/> } /> | |
)} | |
export const MainRoutes = props => | |
<div className='content layout'> | |
<Route exact path="/" component={Landing}/> | |
<Route path={'/contact'} component={Contact}/> | |
<RouteNest path={'/thing'} component={CompoWithSub}> | |
<RouteNest path={'/thing/suba'} component={SubComponentA}/> | |
<RouteNest path={'/thing/subb'} component={SubComponentB}/> | |
</RouteNest> | |
</div> | |
export const CompoWithSub = props => <div>{props.children)</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment