I'm trying to redirect from one page to another using routerLink, but the redirected link doesn't trigger the ngOnInit() method as well as the ActivatedRoute subscription. The redirected page then freezes but there is no error on the console.
So this is my HTML
<a [routerLink]="route(value.id)">link</i></a>
Then this is my component.ts, which returns the url
route = (id: number) => this.routeService.view(id);
This is the redirected component edit.ts
ngOnInit() {
this.route.paramMap.pipe(
takeUntil(this.onDestroy$),
map(params => console.log(params))
).subscribe(x => 'do something')
}
[routerLink]
expects a string or array of strings not a function call. It won't evaluate the function call. Try replacing[routerLink]
with(click)
. – Jason White