getRelativePath

GitHub查看源码
计算从一个 URL 到另一个 URL 的相对路径,常用于动态路由生成和链接处理。

用法

getRelativePath 函数用于获取两个 URL 之间的相对路径。

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)

获取两个 URL 之间的相对路径。

参数

from
string required
起始 URL。
to
string required
目标 URL。

返回值

返回值
string
相对路径。

Changelog

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