T
TanStack9mo ago
genetic-orange

An array of filter with same name. ?category=4&category=3

I am migrating a nextjs app. The nextjs app has a category filter array. How do I do this in tanstack router?
4 Replies
optimistic-gold
optimistic-gold9mo ago
I can help you.
genetic-orange
genetic-orangeOP9mo ago
How do you do this in tanstack router? ?category=4&category=3
absent-sapphire
absent-sapphire9mo ago
By default it serializes/deserializes the params using JSON.parse & JSON.stringify: https://tanstack.com/router/latest/docs/framework/react/guide/custom-search-param-serialization It supports arrays but might not be the way you want it. If you want to customize this you'll need to write your own or use a library as shown in the above link. Query-String: https://github.com/sindresorhus/query-string looks like it supports the format you showed but I've never used the library.
Custom Search Param Serialization | TanStack Router React Docs
Diagram showing idempotent nature of URL search param serialization and deserializationBy default, TanStack Router parses and serializes your URL Search Params automatically using JSON.stringify and JSON.parse. This process involves escaping and unescaping the search string, which is a...
GitHub
GitHub - sindresorhus/query-string: Parse and stringify URL query s...
Parse and stringify URL query strings. Contribute to sindresorhus/query-string development by creating an account on GitHub.
genetic-orange
genetic-orangeOP9mo ago
Aha. So it should customized? Do you think this ?category=4&category=3 is a customized one? This appears in my URL browser ?category=%5B"3"%2C"1"%5D. The items in the array are separated by a comma (%2C). Thanks. I read it. I will try it.

Did you find this page helpful?