I'm having trouble overcoming an issue with react router. The scenario is that i need to pass children routes a set of props from a state parent component and route.
what i would like to do is pass childRouteA
its propsA
, and pass childRouteB
its propsB
. However, the only way i can figure out how to do this is to pass RouteHandler
both propsA
and propsB
which means every child route gets every child prop regardless of whether its relevant. this isnt a blocking issue at the moment, but i can see a time when i'd be using the two of the same component which means that keys on propA will overwritten by the keys by the keys of propB.
# routes
routes = (
<Route name='filter' handler={ Parent } >
<Route name='price' handler={ Child1 } />
<Route name='time' handler={ Child2 } />
</Route>
)
# Parent component
render: ->
<div>
<RouteHandler {...@allProps()} />
</div>
timeProps: ->
foo: 'bar'
priceProps: ->
baz: 'qux'
# assign = require 'object-assign'
allProps: ->
assign {}, timeProps(), priceProps()
This actually works the way i expect it to. When i link to /filters/time
i get the Child2
component rendered. when i go to /filters/price
i get the Child1
component rendered. the issue is that by doing this process, Child1
and Child2
are both passed allProps()
even though they only need price and time props, respectively. This can become an issue if those two components have an identical prop name and in general is just not a good practice to bloat components with unneeded props (as there are more than 2 children in my actual case).
so in summary, is there a way to pass the RouteHandler
timeProps when i go to the time route (filters/time
) and only pass priceProps to RouteHandler
when i go to the price route (filters/price
) and avoid passing all props to all children routes?