用法
toAbsoluteUrl 函数用于将相对 URL 转换为绝对 URL。
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' (已是绝对URL,不变)
API
toAbsoluteUrl(relativeUrl, baseUrl)
将相对 URL 转换为绝对 URL。
参数
relativeUrl
string required
相对 URL。
baseUrl
string required
基础 URL。
返回值
返回值
string
绝对 URL,转换失败返回原字符串。
Changelog
No recent changes