-
-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Route onEnter invokes with next location, but route component renders with old props.location #3299
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
Comments
You can't use There's not much more we can say without more details about what exactly you're trying to do, but you cannot call |
Actually, calling To elaborate specifically on what I'm trying to do: transition routes based on the Something like this (simplified a bit for brevity):
So the general gist here is that when the route changes it extracts a sub-path from the route which that viewport cares about, uses that as the key for the transition group child, and determines whether this route change is "forward" or "backward" for the animation (the actual way that's determined is a bit more complicated, but that part is not relevant and works fine in all cases.) Now this is an example of how
State So the thing is, if the route path changes at the same time that state However, if state Hopefully that makes sense. I apologize this is such a long description. I'm open to any ideas of how to do this differently. I should also mention that I can get around this problem by throwing a Thanks for your help! |
Why do you need those from |
The However the parent route component doesn't check for route change, at this point. If it did also use |
Ok, I think I get what you were saying. I added this to my route component:
I guess I was thinking that kind of "when route changes" thing was exactly what |
You want something like
I'd use the cWRP hook for now. If this comes up in other contexts, we might consider doing things like #2919 to batch the updates, but I think the cWRP solution is the best for what you're trying to do here. |
Makes sense, thanks for the help. |
Version
2.0.0
Description
I'm having an issue React Router
props.location
being stale afteronEnter
changes state during a browser back/forward button press, but not otherwise.I've already posted on StackOverflow here.
In summary (I'm using Chrome, have not tried other browsers yet):
I have
<Route component={MyView} onEnter={enter}>
andenter()
invokessetState()
onMyView
with state based on the new location.browserHistory.pushState()
thenenter()
is invoked andMyView
is rendered withprops.location
as the expected value. This is correct.enter()
is invoked with expected location thenMyView
renders with the oldprops.location
, then renders again a second time with the nextprops.location
. This is a problem becauseMyView
renders with mis-matched data: state has been set based on the new location, but the route shows the old location.This is a problem because I'm trying to use routes to apply page transitions with
ReactCSSTransitionGroup
as shown in the react-router examples, but since theMyView
renders with the new state based on the new position but has the oldprops.location
it fails to apply the transition before re-rendering the view, then when the second render pass happens it transitions out the new state.Is this a known issue? Am I doing something wrong?
The text was updated successfully, but these errors were encountered: