---
title: "removeTrailingSlash"
description: "移除 URL 字符串的尾部斜杠，若无则原样返回，常用于路径规范化和比较。"
seo_title: "removeTrailingSlash"
seo_description: "Remove a trailing slash from a URL and return a new string, normalizing links so identical routes are not duplicated."
canonical_url: "https://core.mhaibaraai.cn/docs/utilities/url/remove-trailing-slash"
---
# removeTrailingSlash

> 移除 URL 字符串的尾部斜杠，若无则原样返回，常用于路径规范化和比较。

## 用法

`removeTrailingSlash` 函数用于移除 URL 的尾部斜杠。

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

removeTrailingSlash('https://example.com/') // 'https://example.com'
removeTrailingSlash('https://example.com/path/') // 'https://example.com/path'
removeTrailingSlash('https://example.com') // 'https://example.com'
```

## API

### `removeTrailingSlash(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.
