Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .changeset/stale-games-shake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@sveltejs/kit": patch
---

fix: `popstate` navigations take `pushState` navigations into account
1 change: 1 addition & 0 deletions packages/kit/src/runtime/client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -1818,6 +1818,7 @@ export function pushState(url, state) {
};

history.pushState(opts, '', resolve_url(url));
has_navigated = true;

page = { ...page, state };
root.$set({ page });
Expand Down
11 changes: 11 additions & 0 deletions packages/kit/test/apps/basics/test/client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -989,6 +989,17 @@ test.describe('Shallow routing', () => {
await expect(page.locator('span')).not.toHaveText(now);
});

test('Does not navigate when going back to shallow route', async ({ baseURL, page }) => {
await page.goto('/shallow-routing/push-state');
await page.locator('[data-id="two"]').click();
await page.goBack();
await page.goForward();

expect(page.url()).toBe(`${baseURL}/shallow-routing/push-state/a`);
await expect(page.locator('h1')).toHaveText('parent');
await expect(page.locator('p')).toHaveText('active: true');
});

test('Replaces state on the current URL', async ({ baseURL, page, clicknav }) => {
await page.goto('/shallow-routing/replace-state/b');
await clicknav('[href="/shallow-routing/replace-state"]');
Expand Down