如何在没有 Angular 前置 "localhost:xxxx" 的情况下导航到外部 URL?

How to navigate to external URL without Angular prepending "localhost:xxxx"?

我正在尝试编写一个守卫,如果用户未登录,则重定向到外部服务(例如 Instagram),

if (!loggedIn) {
   this.location.go(this.instagramLoginUri);
}

其中 location 是 Angular 的 Location 的实例,URI 是

https://api.instagram.com/oauth/authorize/?client_id=xxxxx&redirect_uri=xxxxx&response_type=token

当这个守卫触发时,Angular 尝试导航到

http://localhost:4200/https://api.instagram.com/oauth/authorize/?client_id=xxxxx&redirect_uri=xxxxx&response_type=token

当然失败了。我尝试使用

window.location.href = 'xxxxx'

同样,结果完全相同,所以我不确定这是否确实与 Angular 相关。有什么指点吗?

你能试试这个吗:

 constructor(@Inject(DOCUMENT) private document: any) { }

 if (!loggedIn) {
    this.document.location.href = 'http://instagram.com';
 }