File tree Expand file tree Collapse file tree 1 file changed +8
-20
lines changed
sites/svelte.dev/src/routes/(authed)/repl Expand file tree Collapse file tree 1 file changed +8
-20
lines changed Original file line number Diff line number Diff line change 11import { 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-
183export 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}
You can’t perform that action at this time.
0 commit comments