Skip to content

Route onEnter invokes with next location, but route component renders with old props.location #3299

Closed
@aaronbeall

Description

@aaronbeall

Version

2.0.0

Description

I'm having an issue React Router props.location being stale after onEnter 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}> and enter() invokes setState() on MyView with state based on the new location.

  • When route is changed using browserHistory.pushState() then enter() is invoked and MyView is rendered with props.location as the expected value. This is correct.
  • When route is changed by browser back/forward button enter() is invoked with expected location then MyView renders with the old props.location, then renders again a second time with the next props.location. This is a problem because MyView 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 the MyView renders with the new state based on the new position but has the old props.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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions