From 727a0b847c4a338e5f3e9a657a1f45a5b49e9969 Mon Sep 17 00:00:00 2001 From: Michael Khabarov Date: Sat, 24 Oct 2026 16:21:58 -0300 Subject: [PATCH] fix(vue-router): hide back button on reset tab root Tapping the active tab resets it with router.go(), which leaves the tab's child as the last route in its stack. Switching to another tab and back then copied the child's pushedByRoute onto the tab root, so the root showed a back button. Copy pushedByRoute only when the last route in the stack is the page the tab returns to. Co-Authored-By: Claude Opus 5.5 --- packages/vue-router/src/router.ts | 12 +++++++++- .../base/tests/e2e/playwright/tabs.spec.ts | 22 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/packages/vue-router/src/router.ts b/packages/vue-router/src/router.ts index 95443549c9e..55ffc5f20e6 100644 --- a/packages/vue-router/src/router.ts +++ b/packages/vue-router/src/router.ts @@ -664,7 +664,17 @@ export const createIonRouter = ( const lastRoute = locationHistory.getCurrentRouteInfoForTab( routeInfo.tab ); - routeInfo.pushedByRoute = lastRoute?.pushedByRoute; + /** + * The last route in the tab stack is not always the page + * the tab returns to. After the tab button resets the tab + * with router.go(), its child stays last in the stack, and + * copying the child's pushedByRoute onto the tab root would + * show a back button on the root. + */ + routeInfo.pushedByRoute = + lastRoute?.pathname === routeInfo.pathname + ? lastRoute?.pushedByRoute + : undefined; } else if ( routeInfo.routerAction === "push" && routeInfo.routerDirection === "none" && diff --git a/packages/vue/test/base/tests/e2e/playwright/tabs.spec.ts b/packages/vue/test/base/tests/e2e/playwright/tabs.spec.ts index eb5dc1f0a78..6ccfe37f29c 100644 --- a/packages/vue/test/base/tests/e2e/playwright/tabs.spec.ts +++ b/packages/vue/test/base/tests/e2e/playwright/tabs.spec.ts @@ -36,4 +36,26 @@ test.describe('Tabs', () => { await tabClick(page, 'tab1'); await ionPageVisible(page, 'tab1'); }); + + test('tab root should not be able to go back after resetting the tab and switching tabs', async ({ page }) => { + await page.goto('/tabs/tab1'); + await ionPageVisible(page, 'tab1'); + + await page.locator('div.ion-page[data-pageid=tab1] #child-one').click(); + await ionPageVisible(page, 'tab1childone'); + + // Tapping the active tab resets it via router.go(-1) + await tabClick(page, 'tab1'); + await ionPageVisible(page, 'tab1'); + await ionPageDoesNotExist(page, 'tab1childone'); + + // Pushing tab2 overwrites the history entry of tab1's child + await tabClick(page, 'tab2'); + await ionPageVisible(page, 'tab2'); + + await tabClick(page, 'tab1'); + await ionPageVisible(page, 'tab1'); + await expect(page).toHaveURL(/\/tabs\/tab1(\?|$)/); + await expect(page.locator('div.ion-page[data-pageid=tab1]')).not.toHaveClass(/can-go-back/); + }); });