0

how to open below route in new window. I want this route which is for recorder component to open in new window

  closeDialog(requestType) {
    this.dialogRef.close();
    this.router.navigate(["recorder"], { state: { example: requestType } });
  }

2 Answers2

0

router.navigate is to navigate in the same window. You need to use window.open to open a new tab:

closeDialog(requestType) {
    this.dialogRef.close();
    window.open(`${window.origin}/recorder?exampe=${requestType}`, '_blank');
}

Update

You need to specify the third parameter in the window.open method to open a completely new window:

closeDialog(requestType) {
    this.dialogRef.close();
    window.open(`${window.origin}/recorder?exampe=${requestType}`, '_blank', 'width=1024,height=768');
}

Similar answer here:

JavaScript open in a new window, not tab

critrange
  • 5,652
  • 2
  • 16
  • 47
0

You can still use the Angular Router and use .then

    closeDialog(requestType: any) {
    this.dialogRef.close();
    const link = `${window.origin}/recorder?exampe=${requestType}`;
    this.router.navigate(["recorder"], { state: { example: requestType } }).then((result: any) => {  window.open(link, '_blank'); });
  }

I added the Angular Router link below fit you'd like to see what other cool stuff it can do.

In keeping with the other answers the link should be whatever you declared - so in the example your link was what I placed, I just type checked it in vs code so I believe this should work. https://angular.io/guide/router

chris burd
  • 728
  • 3
  • 9
  • what does `link` refer to in `{ window.open(link, '_blank'); }` – sambhav jain Jun 18 '21 at 12:01
  • I updated my answer sorry - link is your link I updated the answer to show you how to do that properly via a const or let, I used const but it doesn't really matter. Good luck – chris burd Jun 18 '21 at 12:16
  • what above code is doing that it is navigating my current window to component `recorder` component and opening new tab with my home page – sambhav jain Jun 18 '21 at 14:07