-
-
Notifications
You must be signed in to change notification settings - Fork 10.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Props are not passed by Route to components [v4] #4942
Comments
You would need to wrap Route in your own component that passes through its props to the render function directly. Basically, how NavLink works: https://github.com/ReactTraining/react-router/blob/master/packages/react-router-dom/modules/NavLink.js |
Well, it worked :
Why Route doesn't pass props by default though ? |
I ended up creating a
|
I just ran into a similar issue while migrating to v4 and pulled my hair out for quite a while. The docs clearly state that Route children get props too, so
|
hi all! just wondering if there any updates on this issue? is this the expected behavior? |
I am also having trouble passing props into the render prop of . My confusion comes in where I'm supposed to declare the array of props to be inserted into the router line component. |
I could recommend to declare props in react-redux `connect`
`mapStateToProps`
2017-07-26 8:58 GMT+08:00 Kyle Miller <notifications@github.com>:
… I am also having trouble passing props into the render prop of . My
confusion comes in where I'm supposed to declare the array of props to be
inserted into the router line component.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#4942 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ACJseYPjRjFDk-7Xdtn7x6LVlJoW8qp-ks5sRo8rgaJpZM4M4L1Z>
.
|
Is there no way to do this?
|
@acomito that's not really the same thing. You can achieve that, for example, by using |
@skosch Thanks for the quick response. That's the answer I needed to track down. Sorry to clog up the wrong thread! |
(... or even just |
i see... so to get props.location we need to do React.clone for each route? |
Well we shouldn't have to, thus this issue ... 😉 |
True. Yeah one of the pages (SignupPage) has on it.. so I can get my this.props.data there with your fix, but am getting this error still: Failed context type: The context |
I found a solution to this issue The docs make things overly complicated. Just think of it as writing a component like you would in any other location. |
I'm just using the implicit return, anything more complicated doesn't seem to work |
From here you still have access to this.props.someProp inside the child component |
@KyleWMiller, this is the most simple way to pass props, but bad thing is that when i use it i can't see "match.params" property. |
<Route exact path="/conceptions/:id" render={({ match }) => <Conception match={match} {...this.props} />}/> |
@timdorr yeah, it seems i made a mistake i have found it already. |
what a dirt! would be something like this : <Route path="/" component={MyComponent} MyProp={'bla'} /> and a general data share with all routes : <BrowserRouter MyData={'bla'}> |
I also tried this.
This doesn't work in react-router v4, but DOES work in react-router v3. -_- edit - |
Hello,
I use React-route@v4, I have inside my
Router
:My layout contains a components which has a component which has a searchBar. I want the content of the searchBar to change the content of a component of
LandinPage
.I don't know the best way but I end up with a solution which makes
LandingPage
having thesearchRequest
. Now the variable climbed up to the parent component I need to make the variable going down toDrugsList
. So my idea was to give to thechildren
component of the layout the propsearchRequest
by replacing{children}
with :However
<Route path="/" render={props => <LandingPage {...props} />} />
keeps the props for him and doesn't want to give'em toLandingPage
so how should I do ?Actually I'm not only open to understand how making
Route
passing props to its component but also by finding another way (if you think it's better) to make my components communicating.The text was updated successfully, but these errors were encountered: