---
title: "normalizeUrl"
description: "规范化 URL 路径，移除多余斜杠并处理相对路径符号 . 和 ..，返回标准化 URL。"
seo_title: "normalizeUrl"
seo_description: "Normalize a URL path by removing redundant slashes and resolving dot and double-dot segments, producing a clean canonical form."
canonical_url: "https://core.mhaibaraai.cn/docs/utilities/url/normalize-url"
---
# normalizeUrl

> 规范化 URL 路径，移除多余斜杠并处理相对路径符号 . 和 ..，返回标准化 URL。

## 用法

`normalizeUrl` 函数用于规范化 URL 路径(移除多余斜杠、处理 `.` 和 `..`)。

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

normalizeUrl('https://example.com//api///users/')
// 'https://example.com/api/users/'

normalizeUrl('https://example.com/api/../users')
// 'https://example.com/users'

normalizeUrl('/api/./users/../posts')
// '/api/posts'
```

## API

### `normalizeUrl(url)`

规范化 URL 路径。

### 参数

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

### 返回值

**返回值** (`string`): 规范化后的 URL。

## Changelog

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


## Sitemap

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