Skip to content

Commit 6b971a0

Browse files
zonemeenbrc-dd
andauthored
fix(router): hashchange not emitted in certain cases (#3637)
Co-authored-by: Divyansh Singh <[email protected]>
1 parent f6bd99e commit 6b971a0

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

Diff for: src/client/app/router.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ export function createRouter(
180180
: link.href,
181181
link.baseURI
182182
)
183-
const currentUrl = window.location
183+
const currentUrl = new URL(window.location.href) // copy to keep old data
184184
// only intercept inbound html links
185185
if (
186186
!e.ctrlKey &&
@@ -211,7 +211,12 @@ export function createRouter(
211211
window.scrollTo(0, 0)
212212
}
213213
} else {
214-
go(href)
214+
go(href).then(() => {
215+
// do after the route is changed so location.hash in theme code is the new hash
216+
if (hash !== currentUrl.hash) {
217+
window.dispatchEvent(new Event('hashchange'))
218+
}
219+
})
215220
}
216221
}
217222
}

0 commit comments

Comments
 (0)