Angular routerLink / (click) event does not work properly

54 Views Asked by At

I found a strange problem with routerLink and (click) event handler. In such code where I use <br/> tag the second <a..> works well but the first one doesn't work. In case if I change order of <a..> tags to opposit - routerLink starts to work well but (click) doesn't work.

<a routerLink="/profile">Profile</a> <br/> 
<a (click)="logout()">LogoutMe</a>
<ng-content></ng-content>

I tried to put routerLink into <div> without any success

<div><a routerLink="/profile">Profile</a></div> 
<a (click)="logout()">LogoutMe</a>
<ng-content></ng-content>

In such version of code where I replaced <br/> with &nbsp; both links work well

<a routerLink="/profile">Profile</a> &nbsp; 
<a (click)="logout()">LogoutMe</a>
<ng-content></ng-content>

Everything I put inside <ng-content> works correctly.

What can be a reason of such a strange issue? I removed all the code which would affect the issue without any success.

(Angular 17.2.0, Visual Studio template for Angular + ASP.NET core template)

0

There are 0 best solutions below