How to create a url string with query parameters from an object in Angular 5+? : <p>I am trying to create a URL from an object in an Angular 5 SPA. My code looks like the following:</p>

<pre><code>import { UrlTree, UrlSegmentGroup, DefaultUrlSerializer, UrlSegment } from "@angular/router";

const urlTree = new UrlTree();
urlTree.root = new UrlSegmentGroup([new UrlSegment("EndPoint", {})], {});
urlTree.queryParams = {
  "param1": param1Value,
  "param2": param2Value
};
const urlSerializer = new DefaultUrlSerializer();
const url = urlSerializer.serialize(urlTree);
</code></pre>

<p>It does the job, but it seems to include significant overhead for such a trivial job and I am wondering if there is a more straightforward method to obtain the url from the object.</p>

<p>My expectation is to have something simple as:</p>

<pre><code>const url = someSerializer.serialize("/segment1/segment2", { 
  "param1": param1Value,
  "param2": param2Value
})
</code></pre>

<p><strong>Question:</strong> How to create a url string with query parameters from an object in Angular 5+?</p>
