In angular 2 how to preserve query params and add additional query params to route

后端 未结 4 865
一生所求
一生所求 2020-12-29 22:00

For example I am on route /cars?type=coupe and I want to navigate to the same endpoint with additional query params (but keeping existing one). I am trying some

4条回答
  •  不思量自难忘°
    2020-12-29 22:30

    This can be handled using relativeTo and queryParamsHandling properties.

    Try like this:

    constructor(private _route: ActivatedRoute, private _router: Router)
    
    
    this._router.navigate(
        [],
        {
          relativeTo: this._route,
          queryParams: { model: 'renault' },
          queryParamsHandling: 'merge'
     });
    

提交回复
热议问题