fix(react): redirect routes should unmount leaving component, fixes #22022 (#22029)

This commit is contained in:
Ely Lucas
2020-09-04 14:56:20 -06:00
committed by GitHub
parent ec7c023873
commit b11e06cec1
5 changed files with 14 additions and 13 deletions

View File

@ -65,15 +65,18 @@ export class StackManager extends React.PureComponent<StackManagerProps, StackMa
let enteringViewItem = this.context.findViewItemByRouteInfo(routeInfo, this.id);
const leavingViewItem = this.context.findLeavingViewItemByRouteInfo(routeInfo, this.id);
if (!(routeInfo.routeAction === 'push' && routeInfo.routeDirection === 'forward')) {
const shouldLeavingViewBeRemoved = routeInfo.routeDirection !== 'none' && leavingViewItem && (enteringViewItem !== leavingViewItem);
if (shouldLeavingViewBeRemoved) {
leavingViewItem!.mount = false;
//Check if leavingViewItem should be unmounted
if(leavingViewItem) {
if(routeInfo.routeAction === 'replace') {
leavingViewItem.mount = false;
} else if (!(routeInfo.routeAction === 'push' && routeInfo.routeDirection === 'forward')) {
if(routeInfo.routeDirection !== 'none' && (enteringViewItem !== leavingViewItem)) {
leavingViewItem.mount = false;
}
} else if(routeInfo.routeOptions?.unmount) {
leavingViewItem.mount = false;
}
}
if (leavingViewItem && routeInfo.routeOptions?.unmount) {
leavingViewItem.mount = false;
}
const enteringRoute = matchRoute(this.ionRouterOutlet?.props.children, routeInfo) as React.ReactElement;