首页 > 解决方案 > 如何调用外部网址?

问题描述

我正在使用 angular 6 制作应用程序,这里我有两个 url,

其中url 1http://authentication.hello.comurl 2http://application.hello.com

在这里,如果用户通过 url 1 登录,则只能重定向到 url 2。

而如果用户直接将 url 提供为http://application.hello.com,它应该重定向到http://authentication.hello.com进行登录。

为此,我使用了以下内容,

if (localStorage.getItem("isLoggedIn") === "true") {
  return true;
} else {
  window.location.href = "authentication.hello.com";
}

在这里我用过

window.location.href = "authentication.hello.com";

如果未登录,则重定向到身份验证。

但是,如果用户直接将 url 提供为http://application.hello.com,那么它会显示为http://application.hello.com/authentication.hello.com,这里它被添加到给定的 url 但是我需要的是,它应该删除 http://application.hello.com并且应该只有 url 作为http://authentication.hello.com用户可以看到登录屏幕。

对于http://application.hello.com/authentication.hello.comwindow.location.replace("authentication.hello.com")的相同结果也即将到来,而我需要单独加载 url而无需登录。authentication.hello.com application.hello.com

请帮助我使用纯 JavaScript 或打字稿来实现它。

标签: javascriptangulartypescripturlangular-ui-router

解决方案


使用完整 URL 在 window.location.href 中设置值:

window.location.href = "http://authentication.hello.com";

推荐阅读