5

Is there a parameter to provide to the router so that router.navigate() will open in a new tab/window in browser?

Tyler Christian
  • 520
  • 7
  • 14
tigrenok00
  • 155
  • 1
  • 2
  • 11

2 Answers2

2

Create routes just like instructed here.

Set up your app-routing.module.ts ( or just put it in app.module.ts ), place the <router-link> in your app.component.html.

Now, to open a new window from the main page, ( or whatever sub-routes you have created ) just call a function, handled in the main component, that will point to the url of the sub-component route that you setup for the new window.

Example snippits:

app-routing.ts

import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';

import { MainComponent } from './main/main.component'; // main window
import { JclInfoComponent } from './jcl-info/jcl-info.component'; // new window/tab

const appRoutes: Routes = [
    { path: '', component: MainComponent }, // main route
    { path: 'openJcl', component: JclInfoComponent } // new window route
];

@NgModule({
    imports: [
        RouterModule.forRoot( appRoutes )
    ],
    exports: [
        RouterModule
    ]
})
export class AppRoutingModule {}

app.component.html

<router-outlet>
    <!-- Just showing you that you can put things inside this. -->
    <template ngbModalContainer></template> 
</router-outlet>

main.component.html

<button (click)="testMe()">myLabel</button>

main.component.ts

public testMe() {
    window.open( "openJcl" );
}
Tyler Christian
  • 520
  • 7
  • 14
0
this.router.navigate([]).then(result => {  window.open(`/example/test/${my_var}`, '_blank'); });

Angular 2 Routing navigate run in new tab(Use Angular Router naviagte )

drew0530
  • 1
  • 3