diff --git a/packages/react-router/src/ReactRouter/IonRouter.tsx b/packages/react-router/src/ReactRouter/IonRouter.tsx index 7f4023bedb..8be9490061 100644 --- a/packages/react-router/src/ReactRouter/IonRouter.tsx +++ b/packages/react-router/src/ReactRouter/IonRouter.tsx @@ -174,9 +174,18 @@ class IonRouterInner extends React.PureComponent { } else if (routeInfo.routeAction === 'replace') { // Make sure to set the lastPathname, etc.. to the current route so the page transitions out const currentRouteInfo = this.locationHistory.current(); + + /** + * If going from /home to /child, then replacing from + * /child to /home, we don't want the route info to + * say that /home was pushed by /home which is not correct. + */ + const currentPushedBy = currentRouteInfo?.pushedByRoute; + const pushedByRoute = (currentPushedBy !== undefined && currentPushedBy !== routeInfo.pathname) ? currentPushedBy : routeInfo.pushedByRoute; + routeInfo.lastPathname = currentRouteInfo?.pathname || routeInfo.lastPathname; routeInfo.prevRouteLastPathname = currentRouteInfo?.lastPathname; - routeInfo.pushedByRoute = currentRouteInfo?.pushedByRoute || routeInfo.pushedByRoute; + routeInfo.pushedByRoute = pushedByRoute; routeInfo.routeDirection = currentRouteInfo?.routeDirection || routeInfo.routeDirection; routeInfo.routeAnimation = currentRouteInfo?.routeAnimation || routeInfo.routeAnimation; } diff --git a/packages/vue-router/src/router.ts b/packages/vue-router/src/router.ts index 756fd95eba..a84ae558fe 100644 --- a/packages/vue-router/src/router.ts +++ b/packages/vue-router/src/router.ts @@ -202,8 +202,17 @@ export const createIonRouter = (opts: IonicVueRouterOptions, router: Router) => routeInfo.pushedByRoute = lastRoute?.pushedByRoute; } else if (routeInfo.routerAction === 'replace') { const currentRouteInfo = locationHistory.current(); + + /** + * If going from /home to /child, then replacing from + * /child to /home, we don't want the route info to + * say that /home was pushed by /home which is not correct. + */ + const currentPushedBy = currentRouteInfo?.pushedByRoute; + const pushedByRoute = (currentPushedBy !== undefined && currentPushedBy !== routeInfo.pathname) ? currentPushedBy : routeInfo.pushedByRoute; + routeInfo.lastPathname = currentRouteInfo?.pathname || routeInfo.lastPathname; - routeInfo.pushedByRoute = currentRouteInfo?.pushedByRoute || routeInfo.pushedByRoute; + routeInfo.pushedByRoute = pushedByRoute; routeInfo.routerDirection = currentRouteInfo?.routerDirection || routeInfo.routerDirection; routeInfo.routerAnimation = currentRouteInfo?.routerAnimation || routeInfo.routerAnimation; routeInfo.prevRouteLastPathname = currentRouteInfo?.lastPathname; diff --git a/packages/vue/test-app/src/views/Home.vue b/packages/vue/test-app/src/views/Home.vue index 3366c171d9..e09d0a3b96 100644 --- a/packages/vue/test-app/src/views/Home.vue +++ b/packages/vue/test-app/src/views/Home.vue @@ -2,6 +2,9 @@ + + + Test App @@ -54,12 +57,14 @@