title: Angular get full url for a route
body: <p>Wondering if there is a way to retrieve full url for a given route?</p>
  <p>In Angular app you might use <code>router.navigate('...')</code> which will immediately navigate your browser to given route, but is there a way just to build URL string?</p>
  <p>Use case for this is communication with 3rd party services like OAuth2 where I need to provide callback url, I wish not to build it by hands but call something like <code>router.urlFor('callback')</code> which will produce something like <code>&quot;http://localhost:4200/callback&quot;</code></p>
  <p>There is <a href="https://angular.io/api/common/Location" rel="noreferrer">Location</a> service which has <code>prepareExternalUrl</code> but unfortunately it is not what is needed</p>
  <p><strong>Edit</strong>:</p>
  <p>At moment seems that it is not possible and there is no easy out of the box solution, but after looking around at sources find following solution:</p>
  <pre class="lang-js prettyprint-override"><code>const urlTree = router.createUrlTree(['callback'], {
      queryParams: { foo: 'bar' },
      fragment: 'acme'
  });
  const path = location.prepareExternalUrl(urlTree.toString());
  const url = window.location.origin + path;
  console.log(url); // http://localhost:4200/callback?foo=bar#acme
  </code></pre>
  <p><code>createrUrlTree</code> is being called underneath <code>routerLink</code> directive</p>