]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
fix(query): do not normalize query with custom stringifyQuery
authorEduardo San Martin Morote <posva13@gmail.com>
Thu, 25 Jun 2020 11:47:47 +0000 (13:47 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Thu, 25 Jun 2020 11:47:47 +0000 (13:47 +0200)
Fix #328

src/router.ts

index f9a4217d5b4648598333797386dfd151eb361e2a..0820e6ea34ca2d4228909879d28cb92dbc3972e6 100644 (file)
@@ -37,6 +37,7 @@ import {
   normalizeQuery,
   parseQuery as originalParseQuery,
   stringifyQuery as originalStringifyQuery,
+  LocationQuery,
 } from './query'
 import {
   shallowRef,
@@ -340,7 +341,15 @@ export function createRouter(options: RouterOptions): Router {
         // keep the hash encoded so fullPath is effectively path + encodedQuery +
         // hash
         hash,
-        query: normalizeQuery(rawLocation.query),
+        query:
+          // if the user is using a custom query lib like qs, we might have
+          // nested objects, so we keep the query as is, meaning it can contain
+          // numbers at `$route.query`, but at the point, the user will have to
+          // use their own type anyway.
+          // https://github.com/vuejs/vue-router-next/issues/328#issuecomment-649481567
+          stringifyQuery === originalStringifyQuery
+            ? normalizeQuery(rawLocation.query)
+            : (rawLocation.query as LocationQuery),
       },
       matchedRoute,
       {
@@ -396,7 +405,7 @@ export function createRouter(options: RouterOptions): Router {
             2
           )}\n when navigating to "${
             targetLocation.fullPath
-          }". A redirect must contain a name or path.`
+          }". A redirect must contain a name or path. This will break in production.`
         )
         return Promise.reject(new Error('Invalid redirect'))
       }