PrepareParams per-component basis?
alexhawkins opened this issue · 2 comments
alexhawkins commented
When using named components, is it possible to define prepareParams on a per-component basis? I'd like to be able to do this:
<Route
path="shop/product/:name"
component={ProductDetailsMain}>
<IndexRoute
components={{
impactHero: ImpactHero,
nextPrevButtons: NextPrevButtons,
productInfo: ProductInfo,
productReviews: ProductReviews,
relatedProducts: RelatedProducts,
}}
prepareParams={{
relatedProducts={prepareRelatedProductsParams}>
}}
queries={{
impactHero: ViewerQuery,
nextPrevButtons: ViewerQuery,
productInfo: ViewerQuery,
productReviews: ViewerQuery,
relatedProducts: ViewerQuery,
}}
render={{
productInfo: ({ props }) => props ? <ProductInfo {...props} /> : <NamedRouteLoader/>,
}}
/>
</Route>
instead of this
<Route
path="shop/product/:name"
component={ProductDetailsMain}
prepareParams={prepareRelatedProductsParams}>
<IndexRoute
components={{
impactHero: ImpactHero,
nextPrevButtons: NextPrevButtons,
productInfo: ProductInfo,
productReviews: ProductReviews,
relatedProducts: RelatedProducts,
}}
queries={{
impactHero: ViewerQuery,
nextPrevButtons: ViewerQuery,
productInfo: ViewerQuery,
productReviews: ViewerQuery,
relatedProducts: ViewerQuery,
}}
render={{
productInfo: ({ props }) => props ? <ProductInfo {...props} /> : <NamedRouteLoader/>,
}}
/>
</Route>
alexhawkins commented
I need access to router state otherwise i would use prepareParams on the needed Relay query.
taion commented
This isn't possible or more to the point, isn't going to do what you want even if it were – the query aggregation used here means that each param used in all queries must have the same value for all routes.