---
title: "ensureLeadingSlash"
description: "Ensure a path starts with a single leading slash, adding one when missing so route and URL joins stay consistent across your app."
canonical_url: "https://core.mhaibaraai.cn/en/docs/utilities/url/ensure-leading-slash"
---
# ensureLeadingSlash

> Ensure a path starts with a single leading slash, adding one when missing so route and URL joins stay consistent across your app.

## Usage

`ensureLeadingSlash` ensures a path starts with a slash.

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

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

## API

### `ensureLeadingSlash(path)`

Ensure a path starts with a leading slash.

### Parameters

**path** (`string`) *required*: The path string.

### Returns

**returns** (`string`): The path with a leading slash.

## Changelog

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

---

- [GitHub](https://github.com/mhaibaraai/movk-core/blob/main/src/utilities/url/transform.ts)


## Sitemap

See the full [sitemap](https://core.mhaibaraai.cn/sitemap.md) for all pages.
