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

[fix] fixes for firing of hashchange event #2591

Merged
merged 2 commits into from
Oct 12, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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/perfect-ghosts-shake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

[fix] fixes for firing of hashchange event
6 changes: 4 additions & 2 deletions packages/kit/src/runtime/client/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,12 @@ export class Router {

const i1 = url_string.indexOf('#');
const i2 = location.href.indexOf('#');
if (i1 > 0 && i2 > 0 && url_string.substring(0, i1) === location.href.substring(0, i2)) {
const u1 = i1 >= 0 ? url_string.substring(0, i1) : url_string;
const u2 = i2 >= 0 ? location.href.substring(0, i1) : location.href;
benmccann marked this conversation as resolved.
Show resolved Hide resolved
history.pushState({}, '', url.href);
if (u1 === u2) {
benmccann marked this conversation as resolved.
Show resolved Hide resolved
window.dispatchEvent(new HashChangeEvent('hashchange'));
}
history.pushState({}, '', url.href);
this._navigate(url, noscroll ? scroll_state() : null, false, [], url.hash);
event.preventDefault();
});
Expand Down