给定两个绝对 URL:
const from = new URL("https://example.com")
const to = new URL("https://example.com/about")
有没有一种简单可靠的方法来获取它们之间的相对网址? (在这种情况下
about
)
需要处理:
https://example.com/some-page
到 https://example.com/some-other-page
)理想情况下,当用作锚点上的
href
属性时,任何方法都会返回从 URL a 导航到 URL b 的最短 URL。
我最终实现了这个函数,它实现了我想要的功能。