<a routerLink="#Profile">Profile</a> 在 angular 4 中不起作用

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

我在 index.html 文件中使用 <a routerLink="/Profile">Profile</a> 时遇到问题。锚标签没有正常工作。我将 header 菜单放在 index.html 上,并想在 angular 4

中添加以下用于路由的代码
<a href="#Profile" routerLink="/Profile" routerLinkActive="active">
<span class="icon-cogs"></span>Profile</a>

<router-outlet></router-outlet>放在app.component.html

同一行代码 <a routerLink="/Profile">Profile</a> 工作文件,当我将它放入任何其他组件但在 index.html

中不起作用时

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

routerLink 是这样的:

routerLink="/Profile"

所以保持这样:

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

更多详情请阅读:

https://angular.io/guide/router