Skip to content

Commit be4893f

Browse files
committed
fix adding url search params
1 parent c3cfdf1 commit be4893f

File tree

1 file changed

+8
-20
lines changed
  • sites/svelte.dev/src/routes/(authed)/repl

1 file changed

+8
-20
lines changed
Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,5 @@
11
import { redirect } from '@sveltejs/kit';
22

3-
/**
4-
* create a query params string from an object of query parameters
5-
* @param {Record<string, string>} queries
6-
* @returns {string}
7-
*/
8-
function add_query_params(queries) {
9-
const query_array = [];
10-
for (let query in queries) {
11-
if (queries[query] !== null) {
12-
query_array.push(`${query}=${queries[query]}`);
13-
}
14-
}
15-
return query_array.length > 0 ? `?${query_array.join('&')}` : ``;
16-
}
17-
183
export function load({ url }) {
194
const query = url.searchParams;
205
const gist = query.get('gist');
@@ -28,9 +13,12 @@ export function load({ url }) {
2813
}
2914

3015
const id = gist || example || 'hello-world';
31-
const q = add_query_params({
32-
version,
33-
vim
34-
});
35-
throw redirect(301, `/repl/${id}${q}`);
16+
// we need to filter out null values
17+
const q = new URLSearchParams(
18+
Object.entries({
19+
version,
20+
vim
21+
}).filter(([, value]) => value !== null)
22+
).toString();
23+
throw redirect(301, `/repl/${id}?${q}`);
3624
}

0 commit comments

Comments
 (0)