diff --git a/src/v2/guide/migration-vue-router.md b/src/v2/guide/migration-vue-router.md index d9d63c6a0d..bfc8ee85d9 100644 --- a/src/v2/guide/migration-vue-router.md +++ b/src/v2/guide/migration-vue-router.md @@ -236,6 +236,23 @@ if (route.meta.requiresAuth) { {% endraw %} +### [] Syntax for Arrays in Queries removed + +When passing arrays to query parameters the QueryString syntax is no longer `/foo?users[]=Tom&users[]=Jerry`, instead, the new syntax is `/foo?users=Tom&users=Jerry`. Internally, `$route.query.users` will still be an Array, but if there's only one parameter in the query: `/foo?users=Tom`, when directly accessing this route, there's no way for the router to know if we were expecting `users` to be an Array. Because of this, consider adding a computed property and replacing every reference of `$route.query.users` with it: + +```javascript +export default { + // ... + computed: { + // users will always be an array + users () { + const users = this.$route.query.users + return Array.isArray(users) ? users : [users] + } + } +} +``` + ## 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.