Repository navigation
Opt-in document loads for same-origin redirects and navigate() #671
everton-dgn
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
I maintain a multilingual app where
/en/*and/es/*share an origin. We load a new document when the locale changes so the document language and rendered content stay together. Same-locale navigation stays in the router.The awkward case is a redirect returned by an action or query. I catch it in a root
useBeforeLeave, callpreventDefault(), thenlocation.replace(). The root guard subscribes first. A later page guard can cancel router navigation, but cannot undo that call tolocation.replace().Here is a reduced example for
@solidjs/router2.0.0-next.38:Mount
<Router />at/en/start. In Vitest/jsdom, the action rendered the destination throughreplaceState; direct navigation usedpushState. A root-relative query redirect also rendered the destination in the same router. For this locale change, I need a document load. I'd like to keep returning a redirect Response so the action can also serve a plain form POST, rather than make client code handle a returned URL.Would an optional hook such as
documentNavigation: (url: URL) => booleanfit here? The name is just a sketch. It would choose a document load after leave guards accept, before starting the destination transition. For an English document, my predicate would accept/es/*and keep/en/*in the router.The load should preserve the navigation's effective push/replace policy, including one inherited from a pending navigation. An optional plugin could keep unused behavior out of the bundle; its cost would need measurement. A per-redirect signal is another option, but the
redirect()helper lives in@solidjs/web, and choosing the signal requires knowing the current document's locale.There are already useful escape hatches:
target="_self"orrel="external", as discussed in #304.location.assign()orlocation.replace().browserHistory().initcan reload the selected entry instead of notifying the router. My jsdom test confirmed that a page guard can block the traversal, and that acceptance calls a mocked reload callback without rendering the destination. A custom adapter needsscrollRestoration: trueto retain the default restoration behavior.Replacing
history.setalone is too late: the router calls it when the transition settles.These checks ran against
dc1e0b0, withsolid-jsand@solidjs/web2.0.0-rc.14. Real-browser coverage is still needed for document loads, chained redirects and guard retry, plus back/forward preserving the selected entry.All reactions