How to handle arrays in query params?
See original GitHub issueCurrently when I update the route from the client using an array value, it returns the following
/search?current_use='family'¤t_use='other'
I have been wondering how to use arrays in the query params with react-router, as in:
/search?current_use[]='family'¤t_use[]='other'
Issue Analytics
- State:
- Created 9 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Arrays in query params - Medium
Arrays in query params ... The same way there is no concensus over how objects should be represented in query parameters, there is...
Read more >How to pass an array within a query string? - Stack Overflow
Here's what I figured out: Submitting multi-value form fields, i.e. submitting arrays through GET/POST vars, can be done several different ways, ...
Read more >Fun stuff: representing arrays and objects in query strings
Let's see how some popular environments handle it. ... Decoding a query string into an array is done with parse_str.
Read more >Use the Query String to pass an array of selected values ...
You can pass data, including arrays via the Query String when using NavigationManager to navigate to a different page in your Blazor app....
Read more >Angular - How to pass arrays via Query Parameters
This is a quick guide on how to pass an array of values via query string in Angular. This is working in Angular...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi @iamrandys I solved it with the custom history, it’s really simple, I posted the answer in this SO question.
I’m copy pasting the answer here also, I hope it helps you:
As described in the history docs, you need to use a custom history that parses the querystrings like you need.
React-router uses the
query-stringpackage for the parse and stringify functions, doing a quick glance of the code I don’t think it supports your use case, fortunately theqspackage does it with just setting an options.You’ll need to do something like this:
@alejandrodnm you also need to add
{ encode: false }tostringifysecond argument.for more explicit view in url
param%5B%5D=1¶m%5B%5D=10=>param[]=1¶m[]=10