fix(react-router): fix dead code in handleNavigateBack breaking browser forward button

This commit is contained in:
ShaneK
2026-03-10 12:53:58 -07:00
parent f98be5dfcc
commit 0ff44ec629
2 changed files with 20 additions and 1 deletions

View File

@@ -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);

View File

@@ -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');
});
});