i have routes that look like this:
<Router history={syncHistoryWithStore(browserHistory, store)}>
<Route path='/' component={Widget}>
<Route path='/a' component={A} />
<Route path='/b' component={B} expand />
<Route path='/c' component={C} />
</Route>
<Route path='*' component={FourOhFour} />
</Router>
so, Widget
renders A
, B
, or C
as children. Note that on B
i've added my own prop, expand
. usually, Widget
wraps children in some other padded DOM node. when expand
is truthy, i do not want it to be wrapped, and can handle it accordingly. how can i go about achieving this goal?
- in my
Widget
component,props.routes
is a thing, but it contains an array of each route in the tree. - in my
Widget
component,props.route
is a thing, but it doesn't give me a reference to the matched child route.- its like i want a
props.route.child
, in order to sniff forexpand
- its like i want a
i envisioned something like this:
render () {
const { children, route: { child: { expand } } } = this.props
return (
<div {...someOtherProps}>
{expand ? children : <p id="padded-thing">{children}</p>}
</div>
)
}
i'm confident that this is a solved problem, albeit perhaps my strategy is off.
i did see a couple of near dupe threads, like Passing additional parameters in React Router, but given that im asking about a parent route seeing a to-render-child-route, i figured this is different enough. thanks!