Change a single route parameter on the current route in Angular 2

前端 未结 5 1010
慢半拍i
慢半拍i 2021-02-05 03:32

Is it possible to change a single route parameter in the current route, while keeping all the other parameters? This is for use in a paging component, which will route to a new

5条回答
  •  无人及你
    2021-02-05 04:14

    you can use query parameter option instead of parameter it is use like

    in calling component

    const navigationExtras: NavigationExtras = {
      queryParams: { 'param_id': 1, 'param_ids': 2, 'list':[1,2,3] },
    };
    this.router.navigate(['/path'], navigationExtras);
    

    in the called component

      this.route.queryParamMap.map(params =>  params.get('param_id') || 
        'None').subscribe(v => console.log(v));
      this.route.queryParamMap.map(params =>  params.get('param_ids') || 
            'None').subscribe(v => console.log(v));
      this.route.queryParamMap.map(params =>  params.getAll('list') || 
                'None').subscribe(v => console.log(v));
    

提交回复
热议问题