Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

respect replace_state on external navigation where applicable #13303

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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
5 changes: 5 additions & 0 deletions .changeset/dirty-rats-divide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fix: respect `replaceState` on external navigation
14 changes: 10 additions & 4 deletions packages/kit/src/runtime/client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {});
}

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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 });
}
}

Expand Down
Loading