From: Eduardo San Martin Morote Date: Tue, 16 Apr 2019 08:29:50 +0000 (+0200) Subject: handle arrays in strigify query X-Git-Tag: v4.0.0-alpha.0~450 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8bf3a97b150d4a87338a8a9faef1da3833112187;p=thirdparty%2Fvuejs%2Frouter.git handle arrays in strigify query --- diff --git a/src/history/base.ts b/src/history/base.ts index 57aa5f17..5bcf6e35 100644 --- a/src/history/base.ts +++ b/src/history/base.ts @@ -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 diff --git a/src/types/index.ts b/src/types/index.ts index effcbe90..99bd8750 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -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