mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
fix(react-router): fix dead code in handleNavigateBack breaking browser forward button
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user