I'm trying to Open a new page when user clicks on a link. I can't use Angular 2 Router, because it doesn't have any functionalities to redirect to an external URL.
so, i'm using window.location.href="...";
html code:
<button (click)="onNavigate()">Google</tn-submenu-link>
typescript code:
onNavigate(){ //this.router.navigateByUrl("https://www.google.com"); window.location.href="https://www.google.com"; }
But how can I open it in a new tab? when using window.location.href ?
To open the link in a new tab, we can use the <a> element by passing a target attribute with a value _blank . Note: In the example above, we have used the href attribute to pass a link instead of routerLink because the routerLink attribute appends the URL to the current URL path.
Left click -> go to corresponding route / page without a new reload ; Right click -> Open in new tab / window options and would naturally load a new page when using this navigation.
To redirect to an external URL from Angular route without using component, we can set window. location. href to a value in our code.
In the main page section of the editor under the Buttons tab, select a button and turn it on. Then select “redirect to website” from the click action dropdown menu.
onNavigate(){ window.open("https://www.google.com", "_blank"); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With