From f9e3d004c8179f67ef724f5841b5002c5ed8793b Mon Sep 17 00:00:00 2001 From: akonstantinov Date: Mon, 13 Jan 2025 19:39:01 +0300 Subject: [PATCH 1/3] respect replace_state on external navigation where applicable --- packages/kit/src/runtime/client/client.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/kit/src/runtime/client/client.js b/packages/kit/src/runtime/client/client.js index 25cd2c89b528..b0013315b030 100644 --- a/packages/kit/src/runtime/client/client.js +++ b/packages/kit/src/runtime/client/client.js @@ -143,9 +143,15 @@ function clear_onward_history(current_history_index, current_navigation_index) { * Returns a `Promise` that never resolves (to prevent any * subsequent work, e.g. history manipulation, from happening) * @param {URL} url + * @param {Object} [opts] Options related to the navigation + * @param {boolean} [opts.replace_state] If `true`, will replace the current `history` entry rather than creating a new one with `pushState` */ -function native_navigation(url) { - location.href = url.href; +function native_navigation(url, opts = {}) { + if (opts.replace_state) { + location.replace(url.href); + } else { + location.href = url.href; + } return new Promise(() => {}); } @@ -1375,7 +1381,7 @@ async function navigate({ 404 ); } else { - return await native_navigation(url); + return await native_navigation(url, { replace_state }); } } else { navigation_result = await server_fallback( @@ -1423,7 +1429,7 @@ async function navigate({ if (updated) { // Before reloading, try to update the service worker if it exists await update_service_worker(); - await native_navigation(url); + await native_navigation(url, { replace_state }); } } From dfcb5104a7e05edf8aaa28de70172e59d3f7df6a Mon Sep 17 00:00:00 2001 From: akonstantinov Date: Tue, 14 Jan 2025 09:32:54 +0300 Subject: [PATCH 2/3] changeset --- .changeset/dirty-rats-divide.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/dirty-rats-divide.md diff --git a/.changeset/dirty-rats-divide.md b/.changeset/dirty-rats-divide.md new file mode 100644 index 000000000000..ca46b749a4e9 --- /dev/null +++ b/.changeset/dirty-rats-divide.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': patch +--- + +respect `replaceState` on external navigation From fcaa948d0d5e01bbe72cb6933a0028017463955e Mon Sep 17 00:00:00 2001 From: Simon H <5968653+dummdidumm@users.noreply.github.com> Date: Wed, 15 Jan 2025 17:38:32 +0100 Subject: [PATCH 3/3] Update .changeset/dirty-rats-divide.md --- .changeset/dirty-rats-divide.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/dirty-rats-divide.md b/.changeset/dirty-rats-divide.md index ca46b749a4e9..f02a208e96e0 100644 --- a/.changeset/dirty-rats-divide.md +++ b/.changeset/dirty-rats-divide.md @@ -2,4 +2,4 @@ '@sveltejs/kit': patch --- -respect `replaceState` on external navigation +fix: respect `replaceState` on external navigation