javascript - JS 中的重路由

标签 javascript url-routing

例如,有人有网站“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/

相关文章:

javascript - 了解 D3 使用嵌套内容进入、更新和退出选择

javascript - 将 z-index 分配给 Javascript 插件

php - MVC php 应用程序中的 RewriteRule

c# - 从当前上下文推断的 T4MVC 可选参数

ruby-on-rails-3.1 - 具有可选范围 ":locale"的 Rails 路由

c# - asp mvc 核心 url 本地化

python - 500 内部服务器错误 : Python Bottle API

javascript - 将音频文件保存在 Rails 中

javascript - CSS:是否有一个单位等同于 vh + vw?

javascript - 动画调整 jquery 对话框的内容