From fc88613fefa019a3b695a2c6e10c85cd3ce79ae8 Mon Sep 17 00:00:00 2001 From: Liam DeBeasi Date: Mon, 11 Dec 2023 12:31:27 -0500 Subject: [PATCH] fix(react): use custom animation when going back after a replace (#28674) Issue number: resolves #28673 --------- ## What is the current behavior? When reviewing https://github.com/ionic-team/ionic-framework/pull/28671 I noticed a bug where the custom animation was not used when going back after a replace. `handleNavigate` will override whatever is in `incomingRouteParams`. Since we were passing `routeAnimation` (which is `undefined`), it was overriding the animation we set in `handleNavigateBack`. ## What is the new behavior? - `routeAnimation` is no longer overridden ## Does this introduce a breaking change? - [ ] Yes - [x] No ## Other information Dev build: `7.6.1-dev.11702048520.13c82dad` --- packages/react-router/src/ReactRouter/IonRouter.tsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/react-router/src/ReactRouter/IonRouter.tsx b/packages/react-router/src/ReactRouter/IonRouter.tsx index 16b81d64e2..a21d53c045 100644 --- a/packages/react-router/src/ReactRouter/IonRouter.tsx +++ b/packages/react-router/src/ReactRouter/IonRouter.tsx @@ -244,11 +244,17 @@ class IonRouterInner extends React.PureComponent { if (routeInfo && routeInfo.pushedByRoute) { const prevInfo = this.locationHistory.findLastLocation(routeInfo); if (prevInfo) { + /** + * This needs to be passed to handleNavigate + * otherwise incomingRouteParams.routeAnimation + * will be overridden. + */ + const incomingAnimation = routeAnimation || routeInfo.routeAnimation; this.incomingRouteParams = { ...prevInfo, routeAction: 'pop', routeDirection: 'back', - routeAnimation: routeAnimation || routeInfo.routeAnimation, + routeAnimation: incomingAnimation, }; if ( routeInfo.lastPathname === routeInfo.pushedByRoute || @@ -270,7 +276,7 @@ class IonRouterInner extends React.PureComponent { const goBack = history.goBack || history.back; goBack(); } else { - this.handleNavigate(prevInfo.pathname + (prevInfo.search || ''), 'pop', 'back', routeAnimation); + this.handleNavigate(prevInfo.pathname + (prevInfo.search || ''), 'pop', 'back', incomingAnimation); } } else { this.handleNavigate(defaultHref as string, 'pop', 'back', routeAnimation);