Closed thomasthiebaud closed 7 years ago
Hey @thomasthiebaud!
Yeah, you should be able to do this.
I am not 100% about what you are trying to achieve and what your constraints are, but below is a simple example where I have a route object definition (that could refer to a normal or async component), and a generic higher order function to produce routes that accept props.
const homeRoute = {
Component: AsyncHomeRoute, // created with asyncComponent
path: '/',
exact: true
}
// A higher order function that accepts a "route" object and produces
// a Route component that accepts props
const routeWithProps = route => props => {
const { Component, exact, path } = route
return (
<Route
path={path}
exact={exact}
render={routerProps => <Component {...routerProps} {...props} />}
/>
)
}
const HomeRouteWithProps = routeWithProps(homeRoute)
<HomeRouteWithProps foo="bar" />
Hope this helps.
Thanks a lot, shame on me for not finding it
Ain't no shame in programming. Sometimes we just need a different perspective. 😊
I am using
react-router v4
and I have this codeWhere
LazilyLoad
is my own async component. I would like to switch toreact-async-component
since your code is way better, but I cannot manage to send props to the resolved component.Right now I have this code (where
route.component
returnSystem.import(...)
)But I get
since I not longer have
routes={route.routes}
So, is it possible to send props to a resolved component ? If yes, how ? If no, is it desired feature that maybe I can try to implement and PR ?