title: How do I change the base URL dynamically in Angular 2 routing?
body: <p>Currently, I have routing set up in my project. Every new user is redirected to:</p>
  
  <blockquote>
    <p>localhost:4200/default-path/login</p>
  </blockquote>
  
  <p>Once the user logs in, they're redirected to the home module, which has some child routes the user can navigate to.   </p>
  
  <blockquote>
    <p>localhost:4200/default-path/<strong>home</strong><br>
    localhost:4200/default-path/<strong>home/account</strong><br>
    localhost:4200/default-path/<strong>home/account/profile</strong><br>
    localhost:4200/default-path/<strong>home/dashboard</strong></p>
  </blockquote>
  
  <p>... and so on.</p>
  
  <p>Now, the part in bold is already set up in the home module, and doesn't need further editing. However, I'd like to change <code>default-path</code> to something else.</p>
  
  <p>Say, each user can belong to one of three projects: Project blue, red or green. This information is available <em>only after</em> the user submits their credentials and hits the login button.</p>
  
  <p>What I'd like for the routes to say <em>after login</em> is:</p>
  
  <blockquote>
    <p>localhost:4200/<strong>project-blue</strong>/home<br>
    localhost:4200/<strong>project-red</strong>/home<br>
    localhost:4200/<strong>project-green</strong>/home  </p>
  </blockquote>
  
  <p>Bear in mind, the parts in bold are NOT different modules with different associated components, they're just constants I'd like to see in the URL.</p>
  
  <p>Currently, my <code>&lt;base&gt;</code> tag in the index is like <code>&lt;base href='/'&gt;</code> I'm trying to edit this attribute. What I've got is something like:</p>
  
  <pre><code>processLoginSuccess(loginTicket): void {
      const routeName = loginTicket.baseUrl // returns 'project-red'
      let b = document.getElementsByTagName('base')[0]
      b.setAttribute('href', routeName )
  
      this._router.navigate(['/home']);
  }
  </code></pre>
  
  <p>But this doesn't seem to work. </p>
  
  <p>Any ideas?</p>