Passing strings as route parameters in Angular without encoding

I am trying to pass a string using this code:

  this.router.navigate(['/systems', params.toString()]);

The route parameter is then added to the URL to call the API. params.toString()- change_user=2258. When it is sent through the browser, it changes to change_user%3D2558in the URL. When I use the developer tools to see what was sent to the API, it was changed to NaN.
How to pass a string through a router so that I can directly add it to the API string?

Edit: the variable paramsis of type URLSearchParams(). This is how I try to extract the parameter:

this.route.paramMap.switchMap((params: ParamMap) => 
this.httpService.getSites(+params.get('params')))
.subscribe(sites => this.sites = sites);
+4
source share
2 answers

So here is how I fixed it:

, , - + +params.get(). -, , , . params.toString().

+4

, , Angular 2

{ path: 'hero/:id', component: HeroDetailComponent }

1

let id = 2258;
this.router.navigate(['/hero', id]);

ActivatedRoute @angular/router , ,

let id = this.route.snapshot.paramMap.get('id');

2

router.navigateByUrl() ()

router.navigateByUrl('/hero/2258');
+1

Source: https://habr.com/ru/post/1682003/


All Articles