I am using an Angular 2 Router to update the query params in a URL for a search application. I am attempting to replace spaces in a query with + signs. However, + signs are getting encoded. For example:
this.router.navigatebyUrl('?q=one+two');
populates the URL with "?q=one%2Btwo".
In looking at the source code for Angular 2, it looks like the router converts the URL to a UrlTree which uses encodeURIComponent() to encode the url. Because of this, it is impossible to prevent the default encoding.
My current process is that I change the route by doing navigateByUrl as seen above, and then listen for changes with:
this.routeSubscription = this.route.queryParams.subscribe((params: any) => {
this.term = (params.q ? params.q : '');
});
Is there an alternate way to deal with query parameters that would allow me to use my own strategy for url encoding?