javascript - 如何调用外部网址?
问题描述
我正在使用 angular 6 制作应用程序,这里我有两个 url,
其中url 1是http://authentication.hello.com而 url 2是http://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 或打字稿来实现它。
解决方案
使用完整 URL 在 window.location.href 中设置值:
window.location.href = "http://authentication.hello.com";
推荐阅读
- google-cloud-platform - 增加已配置 GCP Cloud Shell 虚拟机的磁盘大小
- java - 使用一些数组和循环的简化策划游戏
- c++ - C++ 类的大小是 40 字节而不是 36
- python - 绘制作为其他 2 列 matplotlib 的红利的数据
- java - (Java 12)当库作为插件加载时 JAXB 不起作用
- angular - 我应该在哪里存储 CSS 文件以在我的 monorepo 中跨应用程序和库使用?
- python - 如何计算从现在到某个时间的小时数
- c# - 已解决 - EF 关系 孩子有很多父母,父母有很多孩子
- ios - Twilio 可编程视频 - 主视图
- vb.net - 如何从只有选定列的 Access 数据库中填充我的 DataGridView?