#navigate with View Transitions via JS?

5 messages · Page 1 of 1 (latest)

silver island
#

I have some pretty simple login logic

if (window.location.pathname.startsWith('/login')) {
  window.location.replace(ROUTES.app);
}       

That routes fine, but it seems to break the View Transitions listener. I get a full page reload instead of a transition.

Is there an API to use in Astro for the new router that handles the View Transitions?

frozen tundraBOT
#
Still waiting for an answer?

It looks like no-one has responded to your question yet. People might not be available right now or don’t know how to answer your question. Want an answer while you wait? Try asking our experimental bot in #1095492539085230272.

silver island
#

Anyone have an answer to this?
It seems modifying the window.location will break Transitions.
But <a href> links and the back/forward buttons work fine.

I think there might be a better way to update the location so that whatever listener Astro is using gets triggered instead of overwriting it?

robust bramble
#

yes, assigning to location does a reload. You can .click() an '<a href=... />' element instead

silver island
#

@robust bramble So, in the case of using a UI Framework. You are suggesting putting invisible anchor elements on the page and then calling the click method on them?
Is there no way to simulate that action without needing an element?

It seems that whatever is listening to these click events would have a use for a more direct set of methods to provide simulated routing events.