diff --git a/src/index.ts b/src/index.ts index 5b140324..e6fa73d7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -72,6 +72,14 @@ export function getParams (input: InputURL): SearchParams { export function joinURL (input0: string, ...input: string[]): string { const path = input.map(parseURL) const baseURL = parseURL(input0) + + for (const p of path) { + p.url.searchParams.forEach((value, key) => { + baseURL.url.searchParams.set(key, value) + }) + } + baseURL.url.pathname = joinPath(baseURL.url.pathname, ...path.map(p => p.url.pathname)) + return normalizeURL(baseURL) } diff --git a/test/join.test.ts b/test/join.test.ts index cfd7097b..c9463eb9 100644 --- a/test/join.test.ts +++ b/test/join.test.ts @@ -10,7 +10,8 @@ describe('joinURL', () => { { input: ['a', 'b/', 'c'], out: 'a/b/c' }, { input: ['a', 'b/', '/c'], out: 'a/b/c' }, { input: ['/a?foo=bar#123', 'b/', 'c/'], out: '/a/b/c/?foo=bar#123' }, - { input: ['http://foo.com', 'a'], out: 'http://foo.com/a' } + { input: ['http://foo.com', 'a'], out: 'http://foo.com/a' }, + { input: ['a?p1=1', 'b?p2=2'], out: 'a/b?p1=1&p2=2' } ] for (const t of tests) {