-
To avoid accidentally creating duplicate content on Google it would be handy if the library could sort the keys in a predictable way. Maybe it's already possible and if so I'm wondering how that can be achieved? As an example setting the following URL shouldn't be possible using the library |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
If your main concern is SEO, you should do this kind of sorting in the metadata canonical URL you declare to crawlers: https://nuqs.47ng.com/docs/seo |
Beta Was this translation helpful? Give feedback.
-
Hmmm yeah that's correct. But wouldn't it be even easier if it was sorted out of the box? That's for example how the popular query-string package works. This would mean that a lot of situations you could skip defining canonicals at all (assuming the query string should be indexable). I for example have to do this right now which would wouldn't be needed if the query params were sorted in a stable order. export const generateMetadata = async ({ searchParams }) => {
const stringifiedSearchParams = stringify(searchParams, { arrayFormat: 'comma' })
const searchString = stringifiedSearchParams ? `?${stringifiedSearchParams}` : ''
return {
alternates: {
canonical: `/foo` + searchString,
},
}
} |
Beta Was this translation helpful? Give feedback.
-
This is available in Complete docs (with demo): https://nuqs-next.47ng.com/docs/options#processing-urlsearchparams <NuqsAdapter
processUrlSearchParams={(search) => {
const entries = Array.from(search.entries())
entries.sort(([a], [b]) => a.localeCompare(b))
return new URLSearchParams(entries)
}}
>
{children}
</NuqsAdapter> |
Beta Was this translation helpful? Give feedback.
This is available in
[email protected]
, feel free to try it:Complete docs (with demo): https://nuqs-next.47ng.com/docs/options#processing-urlsearchparams