Skip to content

Commit

Permalink
fix(react): unmount leaving view when using browser back button, fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
elylucas authored and mhartington committed Oct 31, 2019
1 parent 9372eaf commit 8b29e09
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/react-router/src/ReactRouter/Router.tsx
Expand Up @@ -100,11 +100,13 @@ class RouteManager extends React.Component<RouteComponentProps, RouteManagerStat
* record the view that originally directed to the new view for back button purposes.
*/
enteringView.prevId = enteringView.prevId || leavingView.id;
} else if (action === 'POP') {
direction = leavingView.prevId === enteringView.id ? 'back' : 'none';
} else {
direction = direction || 'back';
leavingView.mount = false;
}
} else if (action === 'REPLACE') {
} else if (direction === 'back' || action === 'REPLACE') {
leavingView.mount = false;
}
} else {
Expand Down

1 comment on commit 8b29e09

@ChristineXYS
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, I am using ionic react version 6.8.0, and I found you still have this kind of issue.

Assume we have page 1 pushing to page 2, page 2 pushing to page 3. The issue happens in this pseudo code:
In page 1:
history.push({
pathname: "page2",
state: {value:1}
});
In page 2:
history.push("page 3");

When navigate back from page 3 to page 2 using history.goBack(); , you can clearly see the action is PUSH instead of POP.

The bug is page 2 was pushed with a state, thus in your code, although setState {direction: "back"} previously, in the end it was replaced by the state {value: 1}, making wrong animation direction.

It can be visible by console.log every history in each page and check the location.state.

Please fix it as soon as possible, which causing push/pop nearly not usable in mobile.

Please sign in to comment.