Angular: How to update queryParams without changing route

后端 未结 8 556
日久生厌
日久生厌 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-07 09:11

    I ended up combining urlTree with location.go

    const urlTree = this.router.createUrlTree([], {
           relativeTo: this.route,
           queryParams: {
               newParam: myNewParam,
           },
           queryParamsHandling: 'merge',
        });
    
        this.location.go(urlTree.toString());
    

    Not sure if toString can cause problems, but unfortunately location.go, seems to be string based.

提交回复
热议问题