19

I want to create a link to the route with multiple parameters and bind them in tempalte. Until now, I've been doing this by executing the function on (click) event, but I was wondering if it's possible within RouterLink's binding.

Here is the function I use to bind parameters:

redirect() {
    this._router.navigate( ['/category', { cat: this.category, page: this.page }]);
}

My route looks like:

{
    path: 'category/:cat/:page',
    component: PostComponent
}

Will I be able to do the same inside routerLink directive?

4

2 に答える 2

40

はい、もちろん、ナビゲーション用にタグを動的routerLinkに形成するために使用できます。href各値がコンポーネント コンテキストに対して評価される配列内の値。

[routerLink]="['/category', category, page ]"
于 2016-09-22T18:33:09.873 に答える