diff --git a/lib/use-routes.js b/lib/use-routes.js index d4f0f52..5cca41b 100644 --- a/lib/use-routes.js +++ b/lib/use-routes.js @@ -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 + }))); } };