Ember 2: Getting an object out of query params in a URL

In Ember 2, for a URL with a query string of ?q[a]=1&q[b]=2, how do I get those params in the controller?

I know how to do it with a single string (q=foo) or an array (q[]=1&q[]=2), but for the above, I can’t make it work.

I am not exactly sure what the question is. When you have “page=4&query=test”


You can still get those parameters on the controller in Ember 2 like this:

Yes, if the URL has this:


I can get the data as two strings like this:

foo: null,
bar: null,
queryParams: ["foo", "bar"]

Then if the URL is like this:


I can get the data into an array of two values like this:

values: []
queryParams: ["values"]

But if I have the following the URL:


How do I get the data into an object like the following?

{ "foo": "1", "bar": "2" }

Something like this has worked for me:

queryParams: ["values"],
values: [],
actions: {
    const values = {
      foo: "1",
      bar: "2"
    this.set("values", values);

Note: You can’t initialize values as an object directly, but if you initialize it as an array, and then set it with an object, it will hold it in the format you described (eg ?values[foo]=1&values[bar]=2)