2017-04-21 12 views
-1

URLを変更せずにURL内のパラメータを変更したいとします。 enter image description hereAngular 2 ActivatedRouteでURL内のIDを変更するにはどうすればよいですか?

私はこのtypescriptですコードがあります。

onRowClicked(event: any) { 
    let currentIdPerson = event.data.IdPerson; 
} 

をそして私はURLにIdPersonを送りたい、私はそれをどのように行うのですか?

+0

これは、ルート構成の様子、どのコンポーネントにrouterLinkまたは 'router.navigate()'コールが含まれているかによって異なります。 –

+0

私はこれを言うなら: 'this.router.navigate(['persons'、currentIdPerson])'それはidの後ろにあるurlの残りを置き換え、私はそれを望んでいない、私はそれを保ちたい –

+0

おそらく 'this.router.navigate(['/ persons'、currentIdPerson])'が必要ですが、これはあなたのルート設定とコードの実行場所に依存します。 –

答えて

0

url of activatedRouteを購読する。 配列へのパスを解析します。配列内のidを置き換えます。 配列に参加してURLを置き換えます。 「this.locationは」場所のタイプである

this.activatedRoute.url.first().subscribe(url => { 
      let path = this.location.path().split('/'); 
      let index = path.indexOf(url[0].path); 
      path.splice(index, count, currenIdPerson); 


      this.location.replaceState(path.join('/')); 


     }); 
1

ES6は角/共通モジュール@からあなたのコンストラクタのコンポーネントで場所.GO方法 だから、インポート場所をサポートしてい

constructor(private location: Location){} 

onRowClicked(event :any){ 
this.location.go(`person\${event.data.personId}\identification`); 
} 

あなたの質問は少しはあります不完全ですが、私はあなたに与えることができる最も簡単な答えだと思います。

関連する問題