]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
handle arrays in strigify query
authorEduardo San Martin Morote <posva13@gmail.com>
Tue, 16 Apr 2019 08:29:50 +0000 (10:29 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Tue, 16 Apr 2019 08:29:50 +0000 (10:29 +0200)
src/history/base.ts
src/types/index.ts

index 57aa5f17d488aaa386967ff2d4eb046f589fa957..5bcf6e351ae9944b29b586eab714b8496f8ef358 100644 (file)
@@ -126,7 +126,6 @@ export abstract class BaseHistory {
     return {
       fullPath: location,
       path,
-      // TODO: transform searchString
       query,
       hash,
     }
@@ -143,7 +142,15 @@ export abstract class BaseHistory {
     for (const key in location.query) {
       if (query.length > 1) query += '&'
       // TODO: handle array
-      query += `${key}=${location.query[key]}`
+      const value = location.query[key]
+      if (Array.isArray(value)) {
+        query += `${key}=${value[0]}`
+        for (let i = 1; i < value.length; i++) {
+          query += `&${key}=${value[i]}`
+        }
+      } else {
+        query += `${key}=${location.query[key]}`
+      }
     }
 
     if (query.length > 1) url += query
index effcbe907411b1e06b240b38dadfe69a66e7a894..99bd875055d012fb0ef8be3185ce072ae7e07142 100644 (file)
@@ -28,17 +28,20 @@ export interface RouteRecord {
 
 type RouteObjectLocation =
   | {
+      // no params because they must be provided by the user
       path: string
       query?: RouteQuery
       hash?: string
     }
   | {
+      // named location
       name: string
       params?: RouteParams
       query?: RouteQuery
       hash?: string
     }
   | {
+      // relative location
       params?: RouteParams
       query?: RouteQuery
       hash?: string