how to replace space with plus(+) url in angular 5?

664 views Asked by At

I need to remove %20 to + sign angular5 following URL http://localhost:4200/listings?item=peter%20in%20england&id=158525

this.router.navigate(['/listings'], { queryParams: { 'item': searchstring, 'id':id}});

http://localhost:4200/listings?item=peter+in+england&id=158525

1

There are 1 answers

1
Surjeet Bhadauriya On

You can use replace method here. It will replace all the space with '+'.

this.router.navigate(['/listings'], { queryParams: { 'item': (searchstring||'').replace(/ /g,"+"), 'id':id}});