Good morning everyone. I tell you my problem.
I had to modify my HTML to remove the routerLink=""
and now do that logic in the controller withrouter.navigate[()]
So the html is something like this:
<ul class="nav">
<li routerLinkActive="active" (click)="changeUrl('0')">
<a>
<span>{{menu[0].title}}</span>
</a>
</li>
<li routerLinkActive="active" (click)="changeUrl('1')">
<a>
<span>{{menu[1].title}}</span>
</a>
</li>
And in the component.ts it is simply controlled in the method changeUrl(orden: number)
that shows the user a confirmation message before doing the
router.navigate[()]
to redirect him in case he accepts.
The problem is that with these changes the routerLink="active"
has stopped working.
Does anybody know how I can fix it?
I answer myself.
The solution that I have found in the end is to directly eliminate the routerLinkActive and set the "active" class with a [class.active]="menu[0].active"
As the menu list is a list of RouteInfo I have added the active value from the component with the instruction: