Skip to content
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

query values should be casted into strings #2131

Closed
Astray-git opened this issue Mar 28, 2018 · 3 comments · Fixed by #3232
Closed

query values should be casted into strings #2131

Astray-git opened this issue Mar 28, 2018 · 3 comments · Fixed by #3232
Labels
contribution welcome fixed on 4.x This issue has been already fixed on the v4 but exists in v3 good first issue improvement

Comments

@Astray-git
Copy link
Contributor

Version

3.0.1

Reproduction link

http://jsfiddle.net/L7hscd8h/6976/

Steps to reproduce

click 'a'

query z added as Number in beforeRouteEnter

typeof query.z is Number

What is expected?

query props should be String

What is actually happening?

no stringify applied on programmatic navigation (next, this.$router.push etc.)

@posva
Copy link
Member

posva commented Mar 28, 2018

This is something that could break existing application, so we may have to wait for a major release.
For the moment you can add your own https://router.vuejs.org/en/api/options.html#parsequery--stringifyquery to overcome this, although JS handles number -> string casting ok

@Astray-git
Copy link
Contributor Author

😢parseQuery is not called on transition query:
https://github.com/vuejs/vue-router/blob/dev/src/util/query.js#L20
extraQuery is typed as { [key: string]: string } and assigned directly without type casting.

Maybe we can add a coercion option for extraQuery?

@Astray-git Astray-git changed the title router won't parse/stringify Programmatic navigated query router won't parse programmatic navigated query Apr 2, 2018
@posva posva changed the title router won't parse programmatic navigated query query values should be casted into strings Nov 22, 2018
@posva
Copy link
Member

posva commented Nov 22, 2018

I have changed my mind regarding not casting (#2131 (comment))
I think we should always cast to string, and regarding ts types, allow strings and numbers for convenience but let users manually cast anything else

@posva posva added fixed on 4.x This issue has been already fixed on the v4 but exists in v3 good first issue contribution welcome labels May 26, 2020
MohamedAhmed12 pushed a commit to MohamedAhmed12/vue-router that referenced this issue Jun 14, 2020
posva added a commit that referenced this issue Jun 18, 2020
* fix(query): Fix query props should be casted into string (fix #2131)

* Apply suggestions from code review

* Update test/unit/specs/query.spec.js

Co-authored-by: mohamed.gad <[email protected]>
Co-authored-by: Eduardo San Martin Morote <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution welcome fixed on 4.x This issue has been already fixed on the v4 but exists in v3 good first issue improvement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants