В моем приложении Angular я определил маршруты:
const appRoutes = [
{ path: '', component: HomeComponent},
{ path: 'news', component: NewsComponent, children: [
{ path: ':id', component: NewsDetailComponent },
]},
{ path: '**', component: PageNotFoundComponent}
];
В моем файле NewsComponent ('/ news') html у меня есть * ngFor l oop для итерации и создания новостей :
<div class="news">
<div class="row">
<div class="col-sm-12 col-md-3" *ngFor="let n of news" (click)="goToNews(n.id)">
<div class="single-news">
<img [src]="n.photoUrl" [alt]="n.headline">
<div class="news-content">
<h3>{{ n.headline }}</h3>
<p>{{ n.content }}</p>
<small>{{ n.author }}, {{ n.date | date }}</small>
</div>
</div>
</div>
</div>
</div>
... и мой файл .ts:
goToNews(id: number) {
this.router.navigate(['news', id]);
}
Проблема в том, что когда я нажимаю на элемент, мой URL-адрес изменяется, но я остаюсь на том же компоненте, который я Я был за все время. Как мне перейти к NewsDetailComponent?