OK, the question is simple, but don't seem to find the answer myself, so please help
I have this routes (simplified):
const routes: Routes = [
{path: '', component: ListPageComponent},
{path: 'd/:id', component: DetailsPageComponent},
{path: ':param1', component: ListPageComponent},
{path: ':param1/:param2', component: ListPageComponent},
{path: ':param1/:param2/:param3', component: ListPageComponent},
{path: '**', component: ListPageComponent}
];
On the ListPageComponent I have some select box filters on top, that trigger onFilter method (simplified):
onFilter(filters: any) {
this._router.navigate([
'myroute/',
this.param1,
this.param2,
this.param3
]);
}
Now, what I would like is when I trigger this method, and I navigate (to the same page component), I don't want the component to run ngOnInit again... just to change the URL params (I am already subscribed to params change - this._route.params.subscribe)
I finally found the solution: Change route params without reloading in angular 2
it is possible just to use location.replaceState, works like a charm in my case!
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