简体   繁体   English

Angular2重定向到外部URL

[英]Angular2 redirect to external URL

I am trying to redirect my Angular2 app to my OAuth2 authentication servers login page. 我正在尝试将Angular2应用重定向到我的OAuth2身份验证服务器登录页面。 This means that I have to redirect to an external URL. 这意味着我必须重定向到外部URL。 I have tested this: 我已经测试过:

this.router.navigate(["/"]).then(result=>{window.location.href = 'http://external-url';});

This works in Firefox but not in Chrome. 这在Firefox中有效,但在Chrome中不起作用。 Isn't there any better way to do this? 没有更好的方法吗? The window.location.href is the only solution I can find. window.location.href是我能找到的唯一解决方案。

I had a similar problem. 我有一个类似的问题。 For me the the redirects worked in Chrome and didn't work in Firefox. 对我来说,重定向在Chrome中起作用,而在Firefox中不起作用。 Try using the following code: 尝试使用以下代码:

window.location.assign( http://external-url ); window.location.assign( http:// external-url );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM