[英]Updating parameters in route Angular
我有一個包含兩個參數的路由,我正在嘗試更新它(只是 url,忘記組件的內容,我也不想刷新頁面或任何東西,只需更新路由)但我不能這樣做。 我的路由:
const routes: Routes = [
{ path: "levs", component: MainComponent },
{ path: "levs/:levType", component: LevDetailsComponent },
{ path: "levs/:levType/:levId", component: EntityDetailsComponent }
];
所以當我在EntityDetailsComponent
和我的 url 是: levs/someLev/someLevId
我有其他實體的列表。 單擊時,我想像這樣更新 url: levs/clickedLev/clickedLevId
。 我嘗試通過路由器鏈接從 html 做到這一點:
<li [routerLink]="[type.entityType, type.entityName]">lev</li>
或者
<li [routerLink]="['/levs', type.entityType, type.entityName]">lev</li>
但在這兩種情況下,它似乎都將其添加到現有路由中,如下所示: levs/someLev/someLevId/levs/clickedLev/clickedLevId
我從 EntityDetailsComponent.ts 嘗試使用路由器:
this.router.navigate('/levs',[this.entityType, this.entityIdentifier]);
並且在參數之前也沒有levs
但結果是一樣的。
我找到了這個解決方案: Update routeparams in angular 5
但是這些人,他們只是在路線上添加數字,我不想增加我的參數而是改變它們,他們的方法對我不起作用。 任何幫助,將不勝感激!
解決方案感謝@armandyjoe 的幫助。 這對我有用,我只需要調整通過的 url 並使用 replaceURL true。
this.router.navigate(["/dct/levs/", this.entityType, this.entityIdentifier], { replaceUrl: true });
this.router.navigate(['/yoururl'], { queryParams: { type: someVariable, entity: someVariable } });
希望這有幫助!
問候
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.