solid-router
solid-router copied to clipboard
Solid Router doesn't handle history.state correctly when using <A>
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.
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.
I agree with this. We should have state present as part of the transition exposed through our own primitives. I don't think there is a good decision either way if we can't tap into our Transitions.
Moving this to router repo as that is where it belongs.