---
title: "isRelativeUrl"
description: "检查字符串是否为相对 URL（不含协议前缀），常用于路径拼接前的类型判断。"
seo_title: "isRelativeUrl"
seo_description: "Check whether a URL is a relative path rather than an absolute or protocol-relative URL, useful before joining it to a base."
canonical_url: "https://core.mhaibaraai.cn/docs/utilities/url/is-relative-url"
---
# isRelativeUrl

> 检查字符串是否为相对 URL（不含协议前缀），常用于路径拼接前的类型判断。

## 用法

`isRelativeUrl` 函数用于检查 URL 是否为相对路径。

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

isRelativeUrl('/path/to/page') // true
isRelativeUrl('./page') // true
isRelativeUrl('../page') // true
isRelativeUrl('https://example.com') // false
```

## API

### `isRelativeUrl(url)`

检查 URL 是否为相对路径。

### 参数

**url** (`string`) *required*: 要检查的 URL。

### 返回值

**返回值** (`boolean`): 是否为相对路径。

## Changelog

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


## Sitemap

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