Vue-router: [Feature] router.go support object-style query string

Created on 8 Feb 2016  路  9Comments  路  Source: vuejs/vue-router

object-style query string maybe a good idea on store some object to query without merge then,
just like jquery.param() do:
obj = { a: { one: 1, two: 2, three: 3 } } ==> a[one]=1&a[two]=2&a[three]=3

1.x intend to implement

All 9 comments

@yyx990803 is there someone implementing this? How can I help?

@paulohp the qs library supports this, maybe see how it's implemented there and submit a PR? :)

I'm working on advanced data-table component and this functionality is "must have", cause I want to implement saving state of filters and pagination in query strings

vue-resource does this. Perhaps vue-resource and vue-router should shared a common vue-url module or similar?

@seaneagan this issue is for 0.7 and is outdated. 2.x already supports this.

It looks like the latest code does support Arrays, but with ?foo=1&foo=2 rather than ?foo[]=1&foo[]=2 (like vue-resource), and it doesn't support objects e.g. ?foo[a]=1&foo[b]=2&foo[c]=3 (like vue-resource), you will instead get e.g. ?foo=[object Object]

Why is this closed? Is this a "wontfix"? As of [email protected] is still unsolved:

{ "filter": { "title": "bla", "actions": 1 } }

returns

?filter=%5Bobject%20Object%5D

Are there any official workarounds?

in vue-router 3 you have to provide a custom and more powerful query parser (like https://github.com/ljharb/qs) to vue-router: https://router.vuejs.org/api/#parsequery-stringifyquery

Thanks, I just found #1259 with the explanation :)

Was this page helpful?
0 / 5 - 0 ratings