Skip to content

Commit a17b963

Browse files
fix(react): replacing route uses new route direction and animation (#28671)
Issue number: resolves #24260 --------- <!-- 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? When replacing a route (`router.push(newRoute, 'none', 'replace')`) the `RouterDirection` from the route being replaced is being used (if it exists) instead of the new one the user specifies. ## What is the new behavior? User-specified `RouteDirection` is used, if it exists. If it doesn't it falls back to the `RouteDirection` of the route being replaced. ## 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 Please see the following comment for why I think the current behavior is incorrect, and why this change is needed: #24260 (comment) --------- Co-authored-by: Liam DeBeasi <[email protected]>
1 parent 8f7d87c commit a17b963

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,15 @@ class IonRouterInner extends React.PureComponent<IonRouteProps, IonRouteState> {
187187
routeInfo.lastPathname = currentRouteInfo?.pathname || routeInfo.lastPathname;
188188
routeInfo.prevRouteLastPathname = currentRouteInfo?.lastPathname;
189189
routeInfo.pushedByRoute = pushedByRoute;
190-
routeInfo.routeDirection = currentRouteInfo?.routeDirection || routeInfo.routeDirection;
191-
routeInfo.routeAnimation = currentRouteInfo?.routeAnimation || routeInfo.routeAnimation;
190+
191+
/**
192+
* When replacing routes we should still prefer
193+
* any custom direction/animation that the developer
194+
* has specified when navigating first instead of relying
195+
* on previously used directions/animations.
196+
*/
197+
routeInfo.routeDirection = routeInfo.routeDirection || currentRouteInfo?.routeDirection;
198+
routeInfo.routeAnimation = routeInfo.routeAnimation || currentRouteInfo?.routeAnimation;
192199
}
193200

194201
this.locationHistory.add(routeInfo);

0 commit comments

Comments
 (0)