diff --git a/renderer/+onRenderClient.js b/renderer/+onRenderClient.js index 4e7fd8f..d3d7621 100644 --- a/renderer/+onRenderClient.js +++ b/renderer/+onRenderClient.js @@ -13,6 +13,13 @@ async function onRenderClient(pageContext) { const app = createApp(Page, pageProps, pageContext); app.mount('#app'); + + if (typeof window !== 'undefined') { + window.addEventListener('popstate', () => { + // force reload when back button is used + window.location.reload(); + }); + } } export { onRenderClient }; diff --git a/src/navigate.js b/src/navigate.js index 7ec9742..9614440 100644 --- a/src/navigate.js +++ b/src/navigate.js @@ -1,3 +1,5 @@ +import events from './events.js'; + export default function navigate(path, query, options = {}) { const curatedQuery = Object.fromEntries(Object.entries(query || {}).map(([key, value]) => (value === undefined ? null : [key, value])).filter(Boolean)); @@ -17,4 +19,6 @@ export default function navigate(path, query, options = {}) { } else { history.pushState({}, '', url); // eslint-disable-line no-restricted-globals } + + events.emit('route', url); }