---
title: "removeLeadingSlash"
description: "移除路径字符串的开头斜杠，若无则原样返回，常用于路径拼接前的预处理。"
seo_title: "removeLeadingSlash"
seo_description: "Remove leading slashes from a path, returning a clean relative segment that is safe to join with other URL or route parts."
canonical_url: "https://core.mhaibaraai.cn/docs/utilities/url/remove-leading-slash"
---
# removeLeadingSlash

> 移除路径字符串的开头斜杠，若无则原样返回，常用于路径拼接前的预处理。

## 用法

`removeLeadingSlash` 函数用于移除 URL 的开头斜杠。

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

removeLeadingSlash('/path/to/page') // 'path/to/page'
removeLeadingSlash('///path') // 'path'
removeLeadingSlash('path') // 'path'
```

## API

### `removeLeadingSlash(url)`

移除 URL 的开头斜杠。

### 参数

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

### 返回值

**返回值** (`string`): 移除开头斜杠后的字符串。

## 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.
