我正在尝试获取通往外部URL的路由。到目前为止,以下是我的示例。
我得到的错误是:
错误错误:未捕获(承诺):错误:无法匹配任何路由。网址段:“ https:/google.com”
错误:无法匹配任何路线。网址段:“ https:/google.com”
这是我的代码
ViolatorLink() {
this.router.navigate(['https://www.google.com/'], {
queryParams: {mid: this.mid}
}
);
}
Run Code Online (Sandbox Code Playgroud)
你需要使用而不是 this.router.navigate
window.location.href = "https://www.google.com";
Run Code Online (Sandbox Code Playgroud)
this.router.navigate将仅导航到路由器配置模块中配置的元素。所以你得到了上面的错误。
理想情况下,您应该window.location.href = "https://www.google.com";对外部URL调用使用,因为在中this.router.navigate查找URL angular routings。
您的功能应类似于:
ViolatorLink() {
window.location.href = "https://www.google.com";
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6432 次 |
| 最近记录: |