Array Query Params inconsistently handled


#1

In a controller I have:

queryParams: {
  selectedCategories: 'categories'
},
selectedCategories: []

When serializing / deserializing the URL Ember ends up generating something like ?categories=%5B14%2C20%2C63%5D, serializing the JSON-stringified array into the URL. This is ok-ish, even if some kind of representation like ```categories[]=14&categories[]=20&categories[]=63`` would be nicer.

However, when I want to pass the params into a new route with {{link-to 'Next' 'some.route' (query-params categories=selectedCategories)}} , the generated URL looks like:

/some/route?categories[]=14&categories[]=20&categories[]=63

So it appears that the treatment of array query params is inconsistent in Ember.

I’m using Ember 1.12.0.


#2

moreover, at least in the router, Ember seems to be able to parse the second variant just fine:

model: function(_, transition) {
  console.log(JSON.stringify(transition.queryParams.categories));
}

logs

["14", "20", "63"]

(btw, why aren’t these parameters available in the first argument of the model hook?)


#3

I think I’m starting to understand where things are going wrong… apparently in (query-params someAttr=someVal), “someAttr” refers to a controller property on the new route’s associated controller. I thought it referred to a URL query parameter.

When I add this code:

queryParams: ['categories'],
categories: []

to the SomeRouteController, the serialization seems to be consistent and the query parameters are available in the first argument of the model hook.

So apparently, I just got the syntax mixed up. The behaviour is still quite strange, though.