-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Approach of conversion for array in query to avoid breaking change #817
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
Merged
kazupon
merged 9 commits into
vuejs:master
from
KingMario:router-migration-array-in-query
Mar 14, 2017
Merged
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
aa5e5c4
Approach of conversion for array in query to avoid breaking change
KingMario 05a1077
Minor revise
KingMario ff6e6be
Minor revise
KingMario 16d8de3
Explain more clearly
KingMario 0153f7b
Minor revise
KingMario 6850013
Use computed property instead
KingMario b58309e
Update migration-vue-router.md
posva 4055ce1
Insist in adding a computed property
KingMario 0b0805a
Update migration-vue-router.md
posva File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -236,6 +236,23 @@ if (route.meta.requiresAuth) { | |
</div> | ||
{% endraw %} | ||
|
||
### [] Syntax for Array of Route Query <sup>removed</sup> | ||
|
||
In URL, [] syntax for array of query is removed. For example, `/foo?users[]=Tom&users[]=Jerry` will be `/foo?users=Tom&users=Jerry` now. | ||
|
||
Since vue-router will treat `?users=Tom` as `query.users == 'Tom'`, unless you are for sure that the array will have more than one element, you should check and convert the query to array if necessary. | ||
|
||
One practical way is to add the following kind of watcher: | ||
|
||
```javascript | ||
'$route.query.users': { | ||
handler(val) { | ||
this.$route.query.users = Array.isArray(val) ? val : [val] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We shouldn't talk about watchers, simply show the example like: const users = Array.isArray(this.$route.query.users)
? users
: [users] Modifying the $route object is a bad idea because it's like a snapshot of the current state, it's supposed to be read only |
||
}, | ||
immediate: true | ||
} | ||
``` | ||
|
||
## Route Matching | ||
|
||
Route matching now uses [path-to-regexp](https://github.com/pillarjs/path-to-regexp) under the hood, making it much more flexible than previously. | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why should we talk about watchers? I think the relevant part is that the user should check if
val
is an array, right?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@posva This watcher can help to convert the query to an array no matter how many elements are provided in the url.