Although this question seems to have popped up before, I can't find an answer that works for me, as the router seems to have changed a lot over the lifetime of angular.
In angular 5 I have a component where I wish to edit a user. I navigate to that component with the following code:
this.router.navigate(['editsingleuser',user.username])
Which will send me to /editsingleuser/bob
Then, from within that component I can also click on a button to edit my own user details, which uses the following code:
this.router.navigate(['editsingleuser',this.user.sub])
Which should send me to /editsingleuser/joe, but does not
Is there a parameter that I can add to the router.navigate
that forces it to load the route, as it seems to be doing some kind of caching?
I have also tried using
[routerLink]="['editsingleuser',user?.sub]"
which also has the same issue
To access the route parameters, we use route. snapshot , which is the ActivatedRouteSnapshot that contains information about the active route at that particular moment in time. The URL that matches the route provides the productId . Angular uses the productId to display the details for each unique product.
What is the difference between [routerLink] and routerLink ? How should you use each one? They're the same directive. You use the first one to pass a dynamic value, and the second one to pass a static path as a string.
I faced the same issue and this solved it in my case
constructor(private router: Router) { this.router.routeReuseStrategy.shouldReuseRoute = function () { return false; }; }
In Angular 8, it is possible to load some other route and then return to the current active one. Just try this:
this.router.navigateByUrl('/', {skipLocationChange: true}) .then(()=>this.router.navigate(['editsingleuser',this.user.sub]));
Credits:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With