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/funny-cycles-travel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

[fix] update current.url on hashchange
2 changes: 2 additions & 0 deletions packages/kit/src/runtime/client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -1321,10 +1321,12 @@ export function create_client({ target, base, trailing_slash }) {
if (hash !== undefined && base === location.href.split('#')[0]) {
// set this flag to distinguish between navigations triggered by
// clicking a hash link and those triggered by popstate
// TODO why not update history here directly?
hash_navigating = true;

update_scroll_positions(current_history_index);

current.url = url;
stores.page.set({ ...page, url });
stores.page.notify();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@
<h1 id="window-hash">{hash}</h1>
<h1 id="page-url-hash">{$page.url.hash}</h1>

<a href="#target">Nav to #ing with anchor tag</a>
<a href="#target">Nav to hash</a>
<a href="/routing/hashes/pagestore">Nav to page</a>
<div id="target">Target</div>
3 changes: 3 additions & 0 deletions packages/kit/test/apps/basics/test/client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,9 @@ test.describe('Routing', () => {
await page.click('[href="#target"]');
expect(await page.textContent('#window-hash')).toBe('#target');
expect(await page.textContent('#page-url-hash')).toBe('#target');
await page.click('[href="/routing/hashes/pagestore"]');
await expect(page.locator('#window-hash')).toHaveText('#target'); // hashchange doesn't fire for these
await expect(page.locator('#page-url-hash')).toHaveText('');
});

test('does not normalize external path', async ({ page }) => {
Expand Down