首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何调用外部url?

问如何调用外部url?
EN

Stack Overflow用户
提问于 2018-09-19 06:37:40
回答 1查看 556关注 0票数 1

我正在使用角6制作一个应用程序,这里我有两个urls,

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

在这里,如果用户是loggen通过url 1将只能重定向到url 2。

但是,如果用户将url直接指定为http://application.hello.com,则应该将其重定向到http://authentication.hello.com进行登录。

我用了以下方法,

代码语言:javascript
复制
if (localStorage.getItem("isLoggedIn") === "true") {
  return true;
} else {
  window.location.href = "authentication.hello.com";
}

在这里我用过

代码语言:javascript
复制
window.location.href = "authentication.hello.com";

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

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

对于window.location.replace("authentication.hello.com")来说,http://application.hello.com/authentication.hello.com的同样结果也即将到来,而我需要单独加载url authentication.hello.com,没有 application.hello.com的,如果不是loggedin的话。

请帮助我实现它使用纯javascript或类型记录。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-09-19 06:44:21

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

代码语言:javascript
复制
window.location.href = "http://authentication.hello.com";
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52399597

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档