在我的 app-routing 中定義路由:
{ path: 'user/:id', component: UserDetailComponent },
定義導航
<a [routerLink]="['/user', user.id]">detail</a>
在 UserDetailComponent 中
this.id = this.route.snapshot.params['id'];
首先。我得到用戶詳細資訊,但是當我重繪 頁面 (userdetail/:id) 時,我收到此訊息錯誤

uj5u.com熱心網友回復:
我認為在 UserDetailComponent 你需要在 NgOnInit 的開頭你需要定義這個:
const urlInfo = this.route.snapshot.paramMap.get('id');
this.getDetails(urlInfo) //in this function you subscribe to the api call
uj5u.com熱心網友回復:
我相信您錯過了斜線位置...在您的路由代碼中,您有一個斜線將用戶與 id 分開,只需將代碼更改為:
<a [routerLink]="['/user', user.id]">detail</a>
對此:
<a [routerLink]="['user/', user.id]">detail</a>
uj5u.com熱心網友回復:
看起來您base="/user"在需要時正在使用您的index.html或其他東西base="/"(假設您正在做普通的事情npm ng serve)
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/490240.html
上一篇:更新TypeScript版本
下一篇:如何按ag網格中的行組計數排序?
