i have this routing module in App Module:
RouterModule.forRoot([
{path: '**', component: SecondoComponent, data : {some_data : '2'}},
{path: 'first', component: PrimoComponent, data : {some_data :'1'}},
{path: 'second', component: SecondoComponent, data : {some_data : '2'}}])
and a bar component with this code:
export class BarComponent implements OnInit {
product;
constructor(router:Router, route:ActivatedRoute) {
router.events
.filter(e => e instanceof NavigationEnd)
.forEach(e => {
this.product = route.root.firstChild.snapshot.data.some_data;
console.log(this.product);
});
}
In product, there is the parameter included in "some_data" in App Module for every route.
The problem is in template:
<app-bar></app-bar>
<nav>
<ul class="nav nav-tabs">
<li>
<a routerLink='/first' >First</a>
</li>
<li>
<a routerLink='/second' >Second</a>
</li>
</ul>
</nav>
<router-outlet></router-outlet>
If i click on a link, the view not change and in console.log i have always the parameter "2" but i click on the "first link".