Skip to content

Commit

Permalink
fix: 参数错误
Browse files Browse the repository at this point in the history
pushState 和 replaceState 的 this 应该是 history 而不是 window,或者直接使用 this
  • Loading branch information
XYShaoKang committed Mar 2, 2022
1 parent 2d44d64 commit ffb74b2
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/content/pages/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ const initUrlChangeEvent = (() => {
const oldReplaceState = history.replaceState

history.pushState = function pushState(...args) {
oldPushState.apply(window, args)
const res = oldPushState.apply(this, args)
window.dispatchEvent(new Event('urlchange'))
return res
}

history.replaceState = function replaceState(...args) {
oldReplaceState.apply(window, args)
const res = oldReplaceState.apply(this, args)
window.dispatchEvent(new Event('urlchange'))
return res
}

window.addEventListener('popstate', () => {
Expand Down

0 comments on commit ffb74b2

Please sign in to comment.