Skip to content

Commit

Permalink
fix: correct context in history.pushState(replaceState)
Browse files Browse the repository at this point in the history
  • Loading branch information
megheaiulian authored and nomego committed Mar 17, 2020
1 parent b8f43d5 commit 31bcf0d
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/use-routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,12 @@ export const useRoutes = (routes, mapUrl) => {
export const navigate = (url, state = null, {
notify = true, replace = true
} = {}) => {
(replace ? history.replaceState : history.pushState)(state, '', url);
(replace ? history.replaceState : history.pushState).call(history, state, '', url);
if (notify) {
window.dispatchEvent(new CustomEvent('popstate', {
bubbles: false
}));
queueMicrotask(() =>
window.dispatchEvent(new CustomEvent('popstate', {
bubbles: false
})));
}
};

0 comments on commit 31bcf0d

Please sign in to comment.