Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular router: (TAB like) navigate - how to change URL without running ngOnInit again

Tags:

angular

router

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)

like image 528
DS_web_developer Avatar asked Dec 18 '17 19:12

DS_web_developer


1 Answers

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!

like image 83
DS_web_developer Avatar answered Sep 28 '22 08:09

DS_web_developer