-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom querystring parser #1259
Comments
This was shipped in 2.4.0 https://router.vuejs.org/en/api/options.html#parsequery--stringifyquery |
It is not very clear from the documentation what the parameters and their types are. From the source, I suppose that // https://github.com/ljharb/qs
import qs from 'qs';
const router = new Router({
routes: [
// ...
],
// set custom query resolver
parseQuery(query) {
return qs.parse(query);
},
stringifyQuery(query) {
var result = qs.stringify(query);
return result ? ('?' + result) : '';
}
}); |
I think we should allow to override the query parsing methods on a per route basis. |
@rayrutjes The url being global, I really think that's a bad idea to change it based on the current component. Appart from that I don't think it's even doable |
I think you are right @posva, per route doesn't make sense. For now, we are going to make sure that we are compatible with what is supported. |
I proposed that already some time ago but vue-router is 8.1kb gziped and qs is 2.6gziped. |
Yes I agree, sadly. |
@posva can you add ganigeorgiev's comment above to the documentation? |
Addition to ganigeorgiev's comment, the query parameters inside routes will be automatically converted url string and parsed as an object when accessing $router.query |
Does parseQuery / stringifyQuery work with the vue-router 4.0 and TS? |
If someone faced an issue overriding
There was an error about undefined qs variable, when i tried to import it at the top of the nuxt.config file. |
Does anyone know why this is getting ignored? It's not even calling those functions
|
In Nuxt 3 you can use this:
import type { RouterConfig } from '@nuxt/schema'
import qs from 'qs'
// https://router.vuejs.org/api/interfaces/routeroptions.html
export default <RouterConfig>{
// Fix router query parser - https://github.com/vuejs/vue-router/issues/1259#issuecomment-1571553624
parseQuery: qs.parse,
stringifyQuery: qs.stringify
} |
Please, add the opportunity to use custom qs lib instead of built-in.
The text was updated successfully, but these errors were encountered: