[英]Angular 2 - should it be routerLink=“theRoute” or [routerLink]=“['the route']”?
[英]Angular routerLink in route with path doesnt route
你好這是我的路線
{
path: 'product/:title/:option',
component: ProductComponent
},
和路由器鏈接
[routerLink]="['/product/'+title]+'/'+option"
但是每當我在組件上說“產品/標題/選項”並且我想路由到“產品/另一個標題/另一個選項”時,搜索欄中的鏈接正在更改,但內容保持原樣......我能做什么用這個做什么?
Angular 在同一路由路徑上時不會重新渲染組件。 您必須觀察組件中的參數變化,並且應該根據參數更新您的組件。
例如:
constructor(
private route: ActivatedRoute
) {}
ngOnInit() {
this.route.params.subscribe(params => {
// Update your content with `params.title` and `params.option`
});
}
嘗試傳遞給routerLink
參數數組https://angular.io/guide/router#link-parameters-array
在您的情況下,它看起來像:
[routerLink]="['product', title, option]"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.