Is your feature request related to a problem? Please describe.
In our app we sometimes need to pass along a search string, e.g. from window.location.search. This works great with the Link component since you can pass it to the href like this:
<Link href={{ pathname: '/about', search: window.location.search }}>
About
</Link>
But if you need to do programmatic routing using push/replace this requires you to pass it as a query object instead (especially if you're using type-safe routing):
push({ pathname: 'about', query: { ... }})
I can't find any simple way of passing an already encoded search string to push or replace. Also it's a little bit unclear to me how the query would be encoded. For example how could one customize how array values are encoded?
Describe the solution you'd like
It'd be great if a search string could be passed to push and replace. This would also enable doing advanced patterns such as:
const searchParams = new UrlSearchParams({ returnTo: window.location.search })
push({ pathname: 'about', search: searchParams.toString() })
Describe alternatives you've considered
Allow passing URLSearchParams to the push and replace methods. Could make sense since that's a fairly well adopted standard. The URLSearchParams standard has some problems though and it doesn't solve supporting different encodings of e.g. array values.
It would be nice if the typed pathnames always allowed suffixing with a search string or hash, like Next.js typedRoutes support. This wouldn't work great with dynamic routes though (push('/[slug]?foo=bar') doesn't really make sense)
Is your feature request related to a problem? Please describe.
In our app we sometimes need to pass along a
searchstring, e.g. fromwindow.location.search. This works great with theLinkcomponent since you can pass it to the href like this:But if you need to do programmatic routing using
push/replacethis requires you to pass it as aqueryobject instead (especially if you're using type-safe routing):I can't find any simple way of passing an already encoded search string to
pushorreplace. Also it's a little bit unclear to me how thequerywould be encoded. For example how could one customize how array values are encoded?Describe the solution you'd like
It'd be great if a
searchstring could be passed topushandreplace. This would also enable doing advanced patterns such as:Describe alternatives you've considered
Allow passing URLSearchParams to the
pushandreplacemethods. Could make sense since that's a fairly well adopted standard. TheURLSearchParamsstandard has some problems though and it doesn't solve supporting different encodings of e.g. array values.It would be nice if the typed pathnames always allowed suffixing with a search string or hash, like Next.js
typedRoutessupport. This wouldn't work great with dynamic routes though (push('/[slug]?foo=bar')doesn't really make sense)