Routing outside of application Angular2

2019-09-14 07:10发布

问题:

I have an app in Angular2 and I need to navigate outside of app. I Have simple view:

...
<a [routerLink]="library.url" target="_blank" (click)="goToPage(library.url)">{{library.url}}</a>
...

and I want to navigate to library.url, I have method for navigation:

      goToPage(url: string)
      {
         //What should be here for navigation outside?
      }

Or exists another way to do that?

回答1:

you can set the global window-location of your Browser in your code, to navigate to your url:

goToPage(url: string): void {
    window.location.href = url;
}