例如,有人有网站“example.com”,上面有一个按钮可以将我路由到“example.com/xyz”(xyz是随机的) ),并且此网址会自动将我路由到另一个网站,例如“google.com”。
"example.com" (button) -> "example.com/xyz" (routing me automatically) to -> "google.com/xyz"
所以,直到我按下按钮,我才会知道我要去哪里。
我想通过向远程站点“example.com”发出请求,从其他站点获取最终网址“google.com/xyz”
编辑:
我想构建一些服务器端代码,当我尝试 GET 到第一个 url 时,它会返回最后一个路由 url
get page http://localhost/tmp/1.html
url changed to http://localhost/tmp/2.html
get page http://localhost/tmp/2.html
url changed to http://localhost/tmp/3.html
get page http://localhost/tmp/3.html
url changed to http://localhost/tmp/4.html
get page http://localhost/tmp/4.html
url changed to http://localhost/tmp/5.html
get page http://localhost/tmp/5.html
started with http://localhost/tmp/1.htmlthen
http://localhost/tmp/2.html, then
http://localhost/tmp/3.html, then
http://localhost/tmp/4.html, then
http://localhost/tmp/5.html
当我得到 1 个 URL 时,它必须在我的服务器代码上返回最后一个 URL
最佳答案
如果我理解,我想你可以简单地使用
window.location = "xyz.html";
这会将您重定向到当前路径中的 xyz.html
来源: https://developer.mozilla.org/en-US/docs/Web/API/Window/location
关于javascript - JS 中的重路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31340048/