---
title: "hasQueryParam"
description: "检查 URL 是否包含指定查询参数，返回布尔值，常用于条件跳转和参数存在性验证。"
seo_title: "hasQueryParam"
seo_description: "Check whether a URL contains a query parameter with the given key, returning a boolean so you can branch on the presence of a flag."
canonical_url: "https://core.mhaibaraai.cn/docs/utilities/url/has-query-param"
---
# hasQueryParam

> 检查 URL 是否包含指定查询参数，返回布尔值，常用于条件跳转和参数存在性验证。

## 用法

`hasQueryParam` 函数用于检查 URL 是否包含指定查询参数。

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

hasQueryParam('https://example.com?page=1', 'page') // true
hasQueryParam('https://example.com?page=1', 'sort') // false
hasQueryParam('https://example.com?flag', 'flag') // true (无值参数)
```

## API

### `hasQueryParam(url, key)`

检查 URL 是否包含指定查询参数。

### 参数

**url** (`string`) *required*: URL 字符串。

**key** (`string`) *required*: 参数名。

### 返回值

**返回值** (`boolean`): 是否包含该参数。

## Changelog

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


## Sitemap

See the full [sitemap](/sitemap.md) for all pages.
