---
title: "setQueryParam"
description: "Set or replace a single query parameter in a URL by key and return a new URL string with the updated value applied."
canonical_url: "https://core.mhaibaraai.cn/en/docs/utilities/url/set-query-param"
---
# setQueryParam

> Set or replace a single query parameter in a URL by key and return a new URL string with the updated value applied.

## Usage

`setQueryParam` sets a query parameter on a URL.

```ts
import { setQueryParam } from '@movk/core'

setQueryParam('https://example.com', 'page', 1)
// 'https://example.com?page=1'

setQueryParam('https://example.com?page=1', 'page', 2)
// 'https://example.com?page=2'

setQueryParam('https://example.com?page=1', 'sort', 'name')
// 'https://example.com?page=1&sort=name'
```

## API

### `setQueryParam(url, key, value)`

Set a query parameter on a URL.

### Parameters

**url** (`string`) *required*: The URL string.

**key** (`string`) *required*: The parameter key.

**value** (`QueryParamValue`) *required*: The parameter value.

### Returns

**returns** (`string`): A new URL string with the updated parameter.

## Changelog

See commit history for [src/utilities/url/query.ts](https://github.com/mhaibaraai/movk-core/commits/main/src/utilities/url/query.ts).

---

- [GitHub](https://github.com/mhaibaraai/movk-core/blob/main/src/utilities/url/query.ts)


## Sitemap

See the full [sitemap](https://core.mhaibaraai.cn/sitemap.md) for all pages.
