#Page won't load when clicking back button with View Transition
6 messages · Page 1 of 1 (latest)
Wrap your script with:
<script>
// astro:page-load event is fired when the page is loaded
document.addEventListener("astro:page-load", () => {
});
</script>
doesn't work
found a hacky solution:
create window.addEventListener('popstate', handlePopState) on the page where window.history.pushState() is executed
inside the handlePopState() is checking if current page is the page where window.history.pushState() is executed and if !document.getElementById("div-inside-the-page") that means the page isn't loaded and do window.location.reload()
this will force reload if the back button is clicked and the link has changed but the page doesn't load
the cons is the listener is always active until a page reload