Skip to content

crelte / std/url / urlWithSearch

Function: urlWithSearch()

ts
function urlWithSearch(url, opts): string | null;

Sets the search params of a URL based on the provided options.

If a value is null, undefined, or an empty string, the corresponding search param will be deleted.

Example

js
urlWithSearch(entry.url, { p: 1 });
// or remove a value
urlWithSearch(entry.url, { p: null });

Parameters

url

| string | URL | BaseRoute | null | undefined

opts

Record<string, string | number | null | undefined>

Returns

string | null