Custom encoding for urls using Angular 2 Router (using a + sign in place of a space)
<p>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:</p>

<pre><code>this.router.navigatebyUrl('?q=one+two');
</code></pre>

<p>populates the URL with "?q=one%2Btwo".</p>

<p>In looking at the source code for Angular 2, it looks like the router converts the URL to a UrlTree <a href="https://github.com/angular/angular/blob/master/modules/%40angular/router/src/url_tree.ts#L360-L363" rel="noreferrer">which uses encodeURIComponent() to encode the url</a>. Because of this, it is impossible to prevent the default encoding.</p>

<p>My current process is that I change the route by doing navigateByUrl as seen above, and then listen for changes with:</p>

<pre><code>this.routeSubscription = this.route.queryParams.subscribe((params: any) =&gt; {
  this.term = (params.q ? params.q : '');
});
</code></pre>

<p>Is there an alternate way to deal with query parameters that would allow me to use my own strategy for url encoding?</p>