I have route with another outlet called compose, for example:
<a [routerLink]="[{outlets: {primary: 'about', compose: 'new-message'}}]">About with compose</a>
When I clicking on the link the URL is:
http://localhost:4200/about(compose:new-message)
That's fine, but when I clicking on this:
<a routerLinkActive="active" [routerLink]="['/home']">Home</a>
The URL is still with the outlet:
http://localhost:4200/home(compose:new-message)
The solution I found is to reset the outlet like this:
<a [routerLink]="[{outlets: {primary: 'home', compose: null}}]">Home</a>
But this is so verbose and annoying, because I will need do this in every link, There is a better way?
When you use [routerlink] it generates href dynamically on the basis of every URL change.
You can work on this as below:
//url = '/home' in ur case
<a (click)='changeRoute(url)'></a>
In your component add below function.
routChange(url){
this.router.navigateByUrl(url);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.