Skip to content

Instantly share code, notes, and snippets.

@soundyogi
Created March 29, 2017 05:37
Show Gist options
  • Save soundyogi/ee72a05c0d704a3bfb3cbbe82fcd3cee to your computer and use it in GitHub Desktop.
Save soundyogi/ee72a05c0d704a3bfb3cbbe82fcd3cee to your computer and use it in GitHub Desktop.
react router v4 nesting
// 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