angularangular4-router

<a routerLink="#Profile">Profile</a> Is not woking in angular 4


I am facing an issue while using <a routerLink="/Profile">Profile</a> in index.html file. The anchor tag didnot work properly. I placed header menu on index.html and want to add the following code for Routing in angular 4

<a href="#Profile" routerLink="/Profile" routerLinkActive="active">
<span class="icon-cogs"></span>Profile</a>

The <router-outlet></router-outlet>is placed in app.component.html

The Same line code <a routerLink="/Profile">Profile</a> working file when i put it in any other component but not working in index.html


Solution

  • You should not put this code inside index.html, it won't work, it should be inside component.

    routerLink be like this :

    routerLink="/Profile"
    

    So keep it like :

    <a routerLink="/Profile" routerLinkActive="active">
    

    For more detail please read :

    https://angular.io/guide/router