按约定,路由模块的名字应该包含 “Routing”,并与导航到的组件所在的模块的名称看齐。
点击跳转路由
1.添加点击事件
<div *ngFor="let hero of heroes" (click)='gotoDetail(); $event.stopPropagation()'>
</div>
gotoDetail(): void {
this.router.navigate(['/detail', this.selectedHero.id]);
}
<div *ngFor="let hero of heroes" [routerLink]="['/detail', hero.id]">
</div>