Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

View Transitions data-astro-reload - not obeyed when using browser back and forward buttons #12852

Closed
1 task
dreamstar-enterprises opened this issue Dec 29, 2024 · 1 comment

Comments

@dreamstar-enterprises
Copy link

Astro Info

5.1.1.

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

I'm getting erratic behaviour when I apply data-astro-reload to an tag.
It works when clicking on the actual a tag, but not when pressing the browser forward and back buttons

What's the expected result?

Should browser back and forward buttongs not obey behaviour attached to the link?

Link to Minimal Reproducible Example

seeabove

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Dec 29, 2024
@martrapp martrapp removed the needs triage Issue needs to be triaged label Dec 30, 2024
@martrapp
Copy link
Member

Hi @dreamstar-enterprises 👋, Yes, that aligns with the documented behavior:

data-astro-reload: an tag attribute to force a full-page navigation

Links with the data-astro-reload attribute will be ignored by the router and a full-page navigation will occur.

It has been that way since Astro 3.0.0. and I'm afraid, changing this now will lead to incompatibilities on existing sites.

You can get the effect you expect by

  • adding a click handler that detects the data-astro-reload attribute on the clicked link
  • calls history.replaceState to set a marker for the current page
  • in an astro:before-preparation listener, detect the marker and call event.preventDefault()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants