Skip to content

Commit fc88613

Browse files
authored
fix(react): use custom animation when going back after a replace (#28674)
Issue number: resolves #28673 --------- <!-- Please do not submit updates to dependencies unless it fixes an issue. --> <!-- Please try to limit your pull request to one type (bugfix, feature, etc). Submit multiple pull requests if needed. --> ## What is the current behavior? <!-- Please describe the current behavior that you are modifying. --> When reviewing #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? <!-- Please describe the behavior or changes that are being added by this PR. --> - `routeAnimation` is no longer overridden ## Does this introduce a breaking change? - [ ] Yes - [x] No <!-- If this introduces a breaking change, please describe the impact and migration path for existing applications below. --> ## Other information <!-- Any other information that is important to this PR such as screenshots of how the component looks before and after the change. --> Dev build: `7.6.1-dev.11702048520.13c82dad`
1 parent e886e3f commit fc88613

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

packages/react-router/src/ReactRouter/IonRouter.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,11 +244,17 @@ class IonRouterInner extends React.PureComponent<IonRouteProps, IonRouteState> {
244244
if (routeInfo && routeInfo.pushedByRoute) {
245245
const prevInfo = this.locationHistory.findLastLocation(routeInfo);
246246
if (prevInfo) {
247+
/**
248+
* This needs to be passed to handleNavigate
249+
* otherwise incomingRouteParams.routeAnimation
250+
* will be overridden.
251+
*/
252+
const incomingAnimation = routeAnimation || routeInfo.routeAnimation;
247253
this.incomingRouteParams = {
248254
...prevInfo,
249255
routeAction: 'pop',
250256
routeDirection: 'back',
251-
routeAnimation: routeAnimation || routeInfo.routeAnimation,
257+
routeAnimation: incomingAnimation,
252258
};
253259
if (
254260
routeInfo.lastPathname === routeInfo.pushedByRoute ||
@@ -270,7 +276,7 @@ class IonRouterInner extends React.PureComponent<IonRouteProps, IonRouteState> {
270276
const goBack = history.goBack || history.back;
271277
goBack();
272278
} else {
273-
this.handleNavigate(prevInfo.pathname + (prevInfo.search || ''), 'pop', 'back', routeAnimation);
279+
this.handleNavigate(prevInfo.pathname + (prevInfo.search || ''), 'pop', 'back', incomingAnimation);
274280
}
275281
} else {
276282
this.handleNavigate(defaultHref as string, 'pop', 'back', routeAnimation);

0 commit comments

Comments
 (0)