Skip to content

Commit

Permalink
fix(core polyfills):‌ Pass a destination object with a url property a…
Browse files Browse the repository at this point in the history
…long with the navigate event.
  • Loading branch information
thet committed Jan 13, 2025
1 parent 2749832 commit 198c369
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/core/polyfills.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,25 @@
// attach events on it.
window.navigation = document.createElement("div");

const create_event = (args) => {
event = new CustomEvent("navigate");

Check failure on line 48 in src/core/polyfills.js

View workflow job for this annotation

GitHub Actions / test

Read-only global 'event' should not be modified
event.destination = { url: args[2] };
return event;
};

// Patch pushState to trigger an `navigate` event on the navigation
// object when the URL changes.
const pushState = window.history.pushState;
window.history.pushState = function () {
pushState.apply(window.history, arguments);
window.navigation.dispatchEvent(new Event("navigate"));
window.navigation.dispatchEvent(create_event(arguments));
};

// Same with replaceState
const replaceState = window.history.replaceState;
window.history.replaceState = function () {
replaceState.apply(window.history, arguments);
window.navigation.dispatchEvent(new Event("navigate"));
window.navigation.dispatchEvent(create_event(arguments));
};
}
})();

0 comments on commit 198c369

Please sign in to comment.