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.

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

No recent changes
Copyright © 2024 - 2026 YiXuan - MIT License