Skip to content

Commit 185e99f

Browse files
Extracting function for URL update
1 parent 9422a77 commit 185e99f

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

packages/kit/src/runtime/client/client.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,6 +1487,10 @@ export function create_client(app, target) {
14871487
callbacks.before_navigate.forEach((fn) => fn(navigation));
14881488
}
14891489

1490+
const url = new URL(location.href, document.baseURI);
1491+
update_url_and_page_store_notifying_with_url(url);
1492+
1493+
14901494
if (should_block) {
14911495
e.preventDefault();
14921496
e.returnValue = '';
@@ -1570,9 +1574,7 @@ export function create_client(app, target) {
15701574

15711575
update_scroll_positions(current_history_index);
15721576

1573-
current.url = url;
1574-
stores.page.set({ ...page, url });
1575-
stores.page.notify();
1577+
update_url_and_page_store_notifying_with_url(url);
15761578

15771579
return;
15781580
}
@@ -1700,15 +1702,6 @@ export function create_client(app, target) {
17001702
'',
17011703
location.href
17021704
);
1703-
} else {
1704-
// when the hash is updated directly through the browser's
1705-
// address bar, the page store needs to be updated
1706-
const url = new URL(location.href, document.baseURI);
1707-
1708-
current.url = url;
1709-
1710-
stores.page.set({ ...page, url });
1711-
stores.page.notify();
17121705
}
17131706
});
17141707

@@ -1728,6 +1721,15 @@ export function create_client(app, target) {
17281721
stores.navigating.set(null);
17291722
}
17301723
});
1724+
1725+
/**
1726+
* @param {URL} url
1727+
*/
1728+
function update_url_and_page_store_notifying_with_url(url) {
1729+
current.url = url;
1730+
stores.page.set({ ...page, url });
1731+
stores.page.notify();
1732+
}
17311733
},
17321734

17331735
_hydrate: async ({

0 commit comments

Comments
 (0)