Reloading page when back button is used.

This commit is contained in:
DebaucheryLibrarian 2024-03-19 03:17:19 +01:00
parent e069fb71b9
commit 95e02d30af
2 changed files with 11 additions and 0 deletions

View File

@ -13,6 +13,13 @@ async function onRenderClient(pageContext) {
const app = createApp(Page, pageProps, pageContext); const app = createApp(Page, pageProps, pageContext);
app.mount('#app'); app.mount('#app');
if (typeof window !== 'undefined') {
window.addEventListener('popstate', () => {
// force reload when back button is used
window.location.reload();
});
}
} }
export { onRenderClient }; export { onRenderClient };

View File

@ -1,3 +1,5 @@
import events from './events.js';
export default function navigate(path, query, options = {}) { export default function navigate(path, query, options = {}) {
const curatedQuery = Object.fromEntries(Object.entries(query || {}).map(([key, value]) => (value === undefined ? null : [key, value])).filter(Boolean)); 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 { } else {
history.pushState({}, '', url); // eslint-disable-line no-restricted-globals history.pushState({}, '', url); // eslint-disable-line no-restricted-globals
} }
events.emit('route', url);
} }