5
votes

I am trying to get a route to an external URL. Below is my example so far.

The error I am getting is:

ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'https:/google.com'

Error: Cannot match any routes. URL Segment: 'https:/google.com'

here is my code

ViolatorLink() {
    this.router.navigate(['https://www.google.com/'], {
        queryParams: {mid: this.mid}
      }
    );
  }
3
You can refer below link in detail Route to external URLNilesh Sutar

3 Answers

8
votes

Ideally, you should use the window.location.href = "https://www.google.com"; for your external URL calls because this.router.navigate looks the URL in angular routings.

Your function should be like:

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

You need to use instead of this.router.navigate

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

this.router.navigate will navigate to only the elements configured in your router config module. So you are getting the error above.

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

I am typing extra characters because SO now needs at least 30 characters in an answer.