如何将window.location设置为特定路径(没有主机)?

我使用窗口定位方法在一段时间后将网页重定向到另一个网页。

该url需要从www.myurl.com/home更改为www.myurl.com/other。 问题是我不知道最终的URL是什么,所以我不能使用绝对链接,它们必须只是一个路径。 这是我到目前为止:

window.location.pathname = "mobility.html" 

您可以在URL之前添加/ ,使它们相对于域根目录(无需对域名进行硬编码)。 像这样:

 window.location = "/mobility.html" 

window.location.assign("/path")也有效。