2016-12-12 14 views
2

router.navigate()がブラウザの新しいタブ/ウィンドウで開くように、ルータに提供するパラメータはありますか?angular2を新しいタブに移動する方法

+0

ルータはそれをサポートしていません。なぜあなたは 'window.open()'を呼び出さないのですか? http://stackoverflow.com/questions/4907843/open-a-url-in-a-new-tab-and-not-a-new-window-using-javascript –

+0

私はルータのURLを開きたい、通常のものではありません...ルータが設定されているものに新しいウィンドウでナビゲートしてください。それは可能ですか? – tigrenok00

+1

それは動作しません。別のタブは別のアプリケーションです。 –

答えて

1

指示通りに経路を作成するhere

app-routing.module.tsを設定してください(またはapp.module.tsに入れてください)。<router-link>app.component.htmlに入れてください。

メインページ(または作成したサブルート)から新しいウィンドウを開くには、メインコンポーネントで処理されたサブコンポーネントルートのURLを指す関数を呼び出します。あなたは新しいウィンドウのためのセットアップを行います。

例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"); 
} 
+0

私は、このメソッドで現在使用しているルートの上にあるDOM要素を操作できないことを発見しました。 –

関連する問題