@@ -51,14 +51,6 @@ export function createAppClient<TApp extends App>(
5151) : AppClient < GetClientRoutes < TApp > > {
5252 const { baseUrl = location . origin , fetch = globalThis . fetch , headers = { } } = options ?? { } ;
5353
54- const buildSearchParams = ( query : Record < string , unknown > ) => {
55- return new URLSearchParams (
56- Object . entries ( query )
57- . filter ( ( [ , value ] ) => value != null )
58- . map ( ( [ key , value ] ) => [ key , String ( value ) ] ) ,
59- ) . toString ( ) ;
60- } ;
61-
6254 const buildPath = ( route : string , params : Record < string , unknown > ) => {
6355 return Object . entries ( params ) . reduce (
6456 ( path , [ key , value ] ) =>
@@ -72,10 +64,13 @@ export function createAppClient<TApp extends App>(
7264
7365 return {
7466 async fetch ( method : string , route : string , inputs : any ) {
75- const searchParams =
76- inputs . query == null ? "" : `?${ buildSearchParams ( inputs . query ) . toString ( ) } ` ;
77- const path = inputs . params == null ? route : buildPath ( route , inputs . params ) ;
78- const url = `${ join ( baseUrl , path ) } ${ searchParams } ` ;
67+ const pathname = inputs . params ? buildPath ( route , inputs . params ) : route ;
68+ const url = new URL ( pathname , baseUrl ) ;
69+ if ( inputs . query ) {
70+ for ( const [ key , value ] of Object . entries ( inputs . query ) ) {
71+ url . searchParams . set ( key , String ( value ) ) ;
72+ }
73+ }
7974
8075 const init = {
8176 body : undefined as BodyInit | undefined ,
@@ -152,11 +147,3 @@ export type CreateAppClientOptions = {
152147 */
153148 headers ?: Record < string , string > ;
154149} ;
155-
156- /** Join string together using `/` without double slashes. */
157- function join ( ...paths : string [ ] ) {
158- return paths
159- . map ( ( path ) => path . replace ( / ^ \/ + | \/ + $ / g, "" ) )
160- . filter ( Boolean )
161- . join ( "/" ) ;
162- }
0 commit comments