---
title: "toAbsoluteUrl"
description: "Resolve a relative URL against a base URL and return the absolute form, so links built from fragments point to the right location."
canonical_url: "https://core.mhaibaraai.cn/en/docs/utilities/url/to-absolute-url"
---
# toAbsoluteUrl

> Resolve a relative URL against a base URL and return the absolute form, so links built from fragments point to the right location.

## Usage

`toAbsoluteUrl` converts a relative URL into an absolute URL.

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

toAbsoluteUrl('/path', 'https://example.com')
// 'https://example.com/path'

toAbsoluteUrl('../other', 'https://example.com/api/users')
// 'https://example.com/api/other'

toAbsoluteUrl('https://other.com', 'https://example.com')
// 'https://other.com' (already absolute, returned as-is)
```

## API

### `toAbsoluteUrl(relativeUrl, baseUrl)`

Convert a relative URL to an absolute URL.

### Parameters

**relativeUrl** (`string`) *required*: The relative URL.

**baseUrl** (`string`) *required*: The base URL.

### Returns

**returns** (`string`): The absolute URL, or the original string if conversion fails.

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