solid-start icon indicating copy to clipboard operation
solid-start copied to clipboard

Solid Router doesn't handle history.state correctly when using <A>

Open pauloevpr opened this issue 2 years ago • 1 comments

When passing history state to <A> like this:

<A href={link()} state={sate()}>

the state is not available in the destination page/component. Calling history.state in the destination component's setup function or even within onMount will always return undefined. This seems to happen because @solidjs/router calls history.pushState after everything else in the navigation workflow happens.

I would imagine that updating the history would ideally be the very first step in the navigation workflow. This is to be consistent with the back/forward navigation triggered by popstate where the history is the very first thing to be updated. If the history is always updated first, then history.state will consistently be available to the page.

pauloevpr avatar Oct 24 '22 10:10 pauloevpr

I think the issue is the router needs to support transitions, so it doesn't want to update the browser history until after that completes.

In the destination component, do you get a better result using the router's useLocation() state instead?

Alternatively, but perhaps not ideal, if you use a plain <a> tag then the url is updated first and the router only finds out about that afterward.

Brendan-csel avatar Oct 29 '22 23:10 Brendan-csel