diff --git a/packages/react-router/src/ReactRouter/IonRouter.tsx b/packages/react-router/src/ReactRouter/IonRouter.tsx index 2ac9b942e5..77fd51553c 100644 --- a/packages/react-router/src/ReactRouter/IonRouter.tsx +++ b/packages/react-router/src/ReactRouter/IonRouter.tsx @@ -490,7 +490,7 @@ export const IonRouter = ({ children, registerHistoryListener }: PropsWithChildr * e.g., `/home` → `/settings` → back to `/home` */ const condition1 = routeInfo.lastPathname === routeInfo.pushedByRoute; - const condition2 = prevInfo.pathname === routeInfo.pushedByRoute && routeInfo.tab === '' && prevInfo.tab === ''; + const condition2 = prevInfo.pathname === routeInfo.pushedByRoute && !routeInfo.tab && !prevInfo.tab; if (condition1 || condition2) { // Record the current location key so browser forward is detectable forwardStack.current.push(currentLocationKeyRef.current); diff --git a/packages/react-router/test/base/tests/e2e/specs/replace-actions.cy.js b/packages/react-router/test/base/tests/e2e/specs/replace-actions.cy.js index 918888dd90..945f65cb30 100644 --- a/packages/react-router/test/base/tests/e2e/specs/replace-actions.cy.js +++ b/packages/react-router/test/base/tests/e2e/specs/replace-actions.cy.js @@ -17,4 +17,23 @@ describe('Replace Action', () => { cy.ionPageVisible('page1'); cy.ionPageDoesNotExist('page2'); }); + + /** + * Tests that the browser forward button works after going back from a + * replace-navigated page. When going back uses navigate(-1) (native browser + * back), the forward entry is preserved in the browser history stack. + * If it falls through to handleNavigate (replace-based), forward is broken. + */ + it('/replace-action > Goto Page2 > Goto Page3 > Browser Back > Browser Forward > Page3 should be visible', () => { + cy.visit(`http://localhost:${port}/replace-action`); + cy.ionPageVisible('page1'); + cy.ionNav('ion-button', 'Goto Page2'); + cy.ionPageVisible('page2'); + cy.ionNav('ion-button', 'Goto Page3'); + cy.ionPageVisible('page3'); + cy.go('back'); + cy.ionPageVisible('page1'); + cy.go('forward'); + cy.ionPageVisible('page3'); + }); });