上传到服务器时路径中断(link 从 js 到 html)

path broke when uploaded to server (link from js to html)

我编写了一个 webside,当我将它上传到服务器时,有一堆坏了(直到现在我只在本地编程,而且并不经常这样做) 除了页面之间的 link 之外,我几乎修复了所有内容。

有效的是 html 到 link 中的“a”元素,但我的大部分页面都在他们的 js 代码中 link 相互连接。

在尝试了一些路径变体(我也尝试了 URL 之后),我将所有文件放在同一个目录中,所以没有路径,但仍然没有用。 我必须假设“window.location.pathname =”result.html”不是正确的方法。

在 Vsc 中,使用实时服务器,它可以工作,但不能在真实服务器上工作

reading documentation 之后它说:

The pathname property of the Location [...] containing the path of the URL for the location, which will be the empty string if there is no path.

所以它只是给你路径,而不是用于重定向。你要找的肯定是 window.location.replace 可以找到哪些文档 here