diff --git a/packages/vue/src/components/IonTabButton.ts b/packages/vue/src/components/IonTabButton.ts index 78eee3f29b8..ee8ea2b1199 100644 --- a/packages/vue/src/components/IonTabButton.ts +++ b/packages/vue/src/components/IonTabButton.ts @@ -71,8 +71,12 @@ export const IonTabButton = /*@__PURE__*/ defineComponent({ * then we must be on a child page and * should direct users back to the root * of the tab. + * + * Without a router outlet, the tabs are not + * tied to the router, so the router must not + * navigate when a tab button is clicked. */ - if (ionRouter !== null) { + if (hasRouterOutlet && ionRouter !== null) { if (prevActiveTab === tab) { if (originalHref !== currentHref) { ionRouter.resetTab(tab, originalHref); diff --git a/packages/vue/test/base/tests/e2e/specs/tabs.cy.js b/packages/vue/test/base/tests/e2e/specs/tabs.cy.js index 1fdc83cf720..1046b2bc374 100644 --- a/packages/vue/test/base/tests/e2e/specs/tabs.cy.js +++ b/packages/vue/test/base/tests/e2e/specs/tabs.cy.js @@ -673,6 +673,20 @@ describe('Tabs', () => { cy.url().should('include', '/tabs-basic'); }); + + it('should not navigate away when clicking the selected tab after visiting tabs with a router outlet', () => { + cy.routerPush('/tabs'); + cy.ionPageVisible('tab1'); + + cy.routerPush('/tabs-basic'); + cy.url().should('include', '/tabs-basic'); + cy.get('ion-tab[data-pageid=tab1]').should('be.visible'); + + cy.get('ion-tabs:has(> ion-tab) ion-tab-button#tab-button-tab1').click(); + + cy.url().should('include', '/tabs-basic'); + cy.get('ion-tab[data-pageid=tab1]').should('be.visible'); + }); }) describe('Swipe to Go Back', () => {