繁体   English   中英

Angular 4 路由到外部 url

[英]Angular 4 route to external url

我正在尝试获取到外部 URL 的路由。 到目前为止,以下是我的示例。

我得到的错误是:

错误错误:未捕获(承诺):错误:无法匹配任何路由。 URL 段:'https://google.com'

错误:无法匹配任何路由。 URL 段:'https://google.com'

这是我的代码

ViolatorLink() {
    this.router.navigate(['https://www.google.com/'], {
        queryParams: {mid: this.mid}
      }
    );
  }

理想情况下,您应该使用window.location.href = "https://www.google.com"; 用于您的外部 URL 调用,因为this.router.navigateangular routings this.router.navigate查找 URL。

你的功能应该是这样的:

ViolatorLink() {
    window.location.href = "https://www.google.com";
  }

您需要使用而不是this.router.navigate

window.location.href = "https://www.google.com";

this.router.navigate将仅导航到路由器配置模块中配置的元素。 所以你得到了上面的错误。

<a [href]="https://www.yourExternalURL.com">

我正在输入额外的字符,因为现在答案中至少需要 30 个字符。

暂无
暂无

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

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