Replies: 1 comment 1 reply
-
I think one way to achieve what you are looking for would be to use a useEffect. check for search params and then set the search params as necessary:
|
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have several routes that I would like to have a default search param, I can see that the hook useSearchParams provides a way to set defaults, however, those defaults do not get reflected in the URL nor can they be factored in to route load requests.
useSearchParams({groupId: '123abc'})
results in a URL without any search parameters ("/example") and obviously you would not be able to access that in your route loader while requesting data.I am wondering what is recommended in this case. A fetcher? setSearchParams? Either of those seems a bit wasteful as you would always be triggering route loading twice, the initial load and then a subsequent one from either fetcher or setSearchParams. Surely you could handle this manually as well by "doing the right thing" in the route loader and defaulting values accordingly for requests and manually modifying the URL to include the correct search parameters, but that is a bit messy and prone to error.
I think the ideal situation would be the ability to specify the default search parameters in the route definition, and have the route matching process update the URL with the search params and therefore make it accessible inside of route data loaders.
With this a request to
/example
would result in/example?groupId=123abc
,route.request.url
would have groupId for data requests, and now obviously useSearchParams would include that as well.Beta Was this translation helpful? Give feedback.
All reactions