-
I'd like to just change the query string of a route without triggering a request to the server (without passing through the Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 8 replies
-
After digging more into it, I discovered that this is possible by using
It would be good to know if there's other ways though, this feels a bit hacky. |
Beta Was this translation helpful? Give feedback.
-
I made an attempt to do this client-only navigation, after sorting out different types of requests/navigations we can make to make the Remix request cheatsheet. Navigation to URLs which only the hash ( // declaratively
<Link to="#color=red"></Link>
// or imperatively
const navigate = useNavigate();
navigate("#color=red") I made a prototype for this idea. It works mostly ok, except one thing, which is in some cases not acceptable:
Prototype: https://stackblitz.com/edit/node-jrnx4b?file=app%2Froutes%2Findex.tsx (Note that I guess if we want the server to notice a parameter in initial rendering but ignore in the following client-side navigations, we'd need another solution. |
Beta Was this translation helpful? Give feedback.
-
Because changing the query string means changing the URL then the correct behavior is to request the loaders. But there's a built-in solution, using That is the correct way to prevent this, and you will need to export that function on every route that may be called by Remix when the query change on your URL, so your route and their parents or child routes. |
Beta Was this translation helpful? Give feedback.
Because changing the query string means changing the URL then the correct behavior is to request the loaders.
But there's a built-in solution, using
unstable_shouldReload
you can check if what changed was the query string and prevent the request (this runs client-side).That is the correct way to prevent this, and you will need to export that function on every route that may be called by Remix when the query change on your URL, so your route and their parents or child routes.