title: Implementing Dynamic Routing in Angular2 (Typescript)
body: <p>RouteConfig class which can be used to decorate a component (@RouteConfig) with routing capabilities has certain route definitions defined for that component. Now, the catch is to have these route definitions injected at runtime (dynamically). </p>
  
  <p>The reason being, let's say I have an application wherein I have to display (UI) and define (decorate) 'n' number of routes, each which corresponds to the account for which the application is loaded and consequently the rights that are associated with that particular account. Thus, having the route definitions pre-defined in the decorator @RouteConfig for a component doesn't make any sense. </p>
  
  <p>My approach is to make a service call every time a new account is loaded. And retrieve the associated routes only and inject them during runtime so as to navigate to other respective components corresponding to each route displayed in the UI for that account.</p>
  
  <pre><code>import { Summary } from './components/summary';
  
  @RouteConfig([
    /*
      Let's say we need a seller dashboard to be displayed...
    */
    //{ path: 'SellerDashboard', component: SellerDashboard }
    { path: '/', component: Summary }
  ])
  class App {
      contactInfo: ContactInfoModel;
      public App(dataService: DataService) {
          this.model = dataService.getContactInfo();
      }
  }
  </code></pre>
  
  <p>In the code snippet above, lets say I wish to load the seller dashboard corresponding to a seller account looged in to my application. Now, it won;t make any sense to display the Point of Sales dashboard or anything thats not relevant to a seller (In our case, seller's inventory dashboard is relevant to a seller). </p>
  
  <p><em>In a gist, injecting only those routes that are required instead of configuring all the routes in the same place.</em></p>
  
  <p><strong>EDIT 1:</strong></p>
  
  <p>This question has a simple use case or a scenario than the duplicate marked on this post (which was asked afterwards). The answers mentioned in this post have simpler approaches and are far more intuitive, too.</p>