13

I have a angular 2 component and need to navigate to another route but in different browser tab. Below code is navigating in same browser tab.

    import { Component } from '@angular/core';
    import { Router } from '@angular/router';

    @Component({
         templateUrl: 'quotes-edit.component.html'
    })

    export class QuoteComponent {
         constructor(private router: Router) {
         }

         this.router.navigate(['quote/add']);
    }
risingTide
  • 1,568
  • 7
  • 25
  • 56
Nimesh Vaghasiya
  • 817
  • 3
  • 12
  • 27

2 Answers2

1

Angular applications are SPA(Single Page Application), which means that the Router is nothing else than a Module to mimic the change of a Route which wouldn't be necessary. You can open redirect in another route in another tab like this

  /**
   * Open url in a new tab
   */
  navigateToNewTab(): void {
    // Here you can get the url
    const { protocol, host } = window.location;
    // Or use the router
    // this.router.url

    const path = '...';

    const url = `${protocol}//${host}/${path}`;
    window.open(url,'_blank');
  }


Ling Vu
  • 3,839
  • 4
  • 16
  • 41
0

You wouldn't use the angular router for this but instead, you could make a function that has the following

 openinbrowserclicked(url) {
    window.open(
      'url',
      '_blank',
      'toolbar=no,resizable=yes,scrollbars=yes'
    );
  }
Nilesh Kesar
  • 357
  • 2
  • 14