无名 发表于 2022-5-8 17:02:48

【LSP】Angular应用的路由指令RouterLink


http://cdn.u1.huluxia.com/g4/M01/65/3E/rBAAdl91PnqAHg7XAACt4WdlvYs450.jpg
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:

http://cdn.u1.huluxia.com/g4/M01/65/3E/rBAAdl91PnuAOVPrAAC3jBPeroI804.png
http://cdn.u1.huluxia.com/g4/M01/65/3E/rBAAdl91PnuAdoCOAAE5xiekwyc925.png
页: [1]
查看完整版本: 【LSP】Angular应用的路由指令RouterLink