Angular: How to update queryParams without changing route

后端 未结 8 555
日久生厌
日久生厌 2020-12-07 09:01

I am trying to update (add, remove) queryParams from a component. In angularJS, it used to be possible thanks to :

$location.search(\'f\', \'filters[]\'); //         


        
8条回答
  •  心在旅途
    2020-12-07 09:03

    If you want to change query params without change the route. see below example might help you: current route is : /search & Target route is(without reload page) : /search?query=love

        submit(value: string) {
          this.router.navigate( ['.'],  { queryParams: { query: value } })
            .then(_ => this.search(q));
        }
        search(keyword:any) { 
        //do some activity using }
    

    please note : you can use this.router.navigate( ['search'] instead of this.router.navigate( ['.']

提交回复
热议问题