#Page won't load when clicking back button with View Transition

6 messages · Page 1 of 1 (latest)

copper rapids
#

the previous link was set using window.history.pushState()

the issue is gone if I remove View Transition

any solution?

halcyon thistle
#

Wrap your script with:

<script>
  // astro:page-load event is fired when the page is loaded
  document.addEventListener("astro:page-load", () => {

  });
</script>
copper rapids
#

doesn't work

copper rapids
#

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

carmine cosmos