T
TanStack12mo ago
ambitious-aqua

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
correct-apricot
correct-apricot12mo ago
I can help you.
ambitious-aqua
ambitious-aquaOP12mo ago
How do you do this in tanstack router? ?category=4&category=3
conscious-sapphire
conscious-sapphire12mo 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.
ambitious-aqua
ambitious-aquaOP12mo 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?