Angular应用的路由指令RouterLink

时间:2022-07-23
本文章向大家介绍Angular应用的路由指令RouterLink,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

Angular应用的路由指令RouterLinkapp Component html源代码:

<h1>{{title}}</h1>
<nav>
    <a routerLink="/heroes">Heroes</a>
  </nav>
<router-outlet></router-outlet>
<app-messages></app-messages>

A routerLink attribute is set to “/heroes”, the string that the router matches to the route to HeroesComponent. The routerLink is the selector for the RouterLink directive that turns user clicks into router navigations. It’s another of the public directives in the RouterModule.

HTML原生标签a的属性routerlLink,是RouterLink指令的选择器,将用户点击转换成navigation. RouterLink是RouterModule里的公有指令。

运行时效果:点击了超链接后,会跳转到localhost:4200/heroes: