I'm trying to reload my navigations in my angular 5.2 application without any success. If the params are unchanged, the angular router will ignore my navigations.
How I navigate:
this.router.navigate(['/search', buildParamsFromSearchCriteria(criteria)]);
This navigates to:
/search;pageSize=20;page=1;orderBy=price;sortDirection=ASCENDING
My module config:
imports: [RouterModule.forRoot(appRoutes, { preloadingStrategy: PreloadAllModules, enableTracing: false, onSameUrlNavigation: 'reload' })],
It can be done in a much simpler way. Below is a small sample code:
in routing.module: "/product/: id / details"
import { ActivatedRoute, Params, Router } from ‘@angular/router’;
export class ProductDetailsComponent implements OnInit {
constructor(private route: ActivatedRoute, private router: Router) {
this.route.params.subscribe(params => {
this.paramsChange(params.id);
});
}
// Call this method on page load
ngOnInit() {
}
// Call this method on change of the param
paramsChange(id) {
}
the general explanation is ... why to destroy already existed component instance and create a new one for the same case when it means performance degradation? It is the exactly the same behavior as using routes pattern /product/:id where the same component instance is also kept for /product/5, /product/6, ...
So you should re-init the component on the base of some emitted event (resolver/guard) and not on the base of OnInit hook because of the same component instance.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With