---
title: "getRelativePath"
description: "Compute the relative path between two URLs, returning a path that navigates from the source location to the target location."
canonical_url: "https://core.mhaibaraai.cn/en/docs/utilities/url/get-relative-path"
---
# getRelativePath

> Compute the relative path between two URLs, returning a path that navigates from the source location to the target location.

## Usage

`getRelativePath` computes the relative path between two URLs.

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

getRelativePath('https://example.com/a/b', 'https://example.com/a/c')
// '../c'

getRelativePath('https://example.com/a', 'https://example.com/a/b/c')
// 'b/c'
```

## API

### `getRelativePath(from, to)`

Get the relative path between two URLs.

### Parameters

**from** (`string`) *required*: The source URL.

**to** (`string`) *required*: The target URL.

### Returns

**returns** (`string`): The relative path.

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