Reputation: 83
I have a route with two parameters in it and Im trying to update it (just the url, forget about the content of the component, also I dont want to refresh the page or anything, just update the route) but I cant do that. My routing:
const routes: Routes = [
{ path: "levs", component: MainComponent },
{ path: "levs/:levType", component: LevDetailsComponent },
{ path: "levs/:levType/:levId", component: EntityDetailsComponent }
];
So when Im in EntityDetailsComponent
and my url is: levs/someLev/someLevId
I have a list of other entities. When clicked, I want to update the url like this: levs/clickedLev/clickedLevId
. I tried to do it from html with router link:
<li [routerLink]="[type.entityType, type.entityName]">lev</li>
or
<li [routerLink]="['/levs', type.entityType, type.entityName]">lev</li>
but in both cases it seems to be addding it to existing route like this:
levs/someLev/someLevId/levs/clickedLev/clickedLevId
I tried from EntityDetailsComponent.ts with router:
this.router.navigate('/levs',[this.entityType, this.entityIdentifier]);
And also without levs
before parameters but the result is the same.
I found this solution: Update routeparams in angular 5
but these guys, they are just adding numbers to the route, I dont want to increment my parameters but change them, their approach doesnt work for me. Any help would be appreciated!
SOLUTION Thanks @armandyjoe for help. This worked for me, I just had to adjust passed url and use replaceURL true.
this.router.navigate(["/dct/levs/", this.entityType, this.entityIdentifier], {
replaceUrl: true
});
Upvotes: 0
Views: 155
Reputation: 123
this.router.navigate(['/yoururl'], { queryParams: { type: someVariable, entity: someVariable } });
Hope this help!
Regards
Upvotes: 2