Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion packages/vue-router/src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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" &&
Expand Down
22 changes: 22 additions & 0 deletions packages/vue/test/base/tests/e2e/playwright/tabs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/);
});
});
Loading