14

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,754
  • 7
  • 31
  • 60
Nimesh Vaghasiya
  • 887
  • 4
  • 13
  • 28

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
  • 4,740
  • 5
  • 24
  • 45
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
  • 387
  • 2
  • 15