title: Angular - Conditional module load on lazy loading
body: <p>I wanna load different module in root route of my application based on the group/role of current user. I have a service class where I can get the group of current user, then I would like to load lazy module based on this group. The question is: How can I do that: How can I define a conditional module lazy loading (<em>loadChildren property</em>) ? What is the best way to do that? </p>
  
  <p>I think  these solutions:</p>
  
  <p>1 - Inject the service in app-routing.module and do an if else clause on loadChildren property like this: <code>loadChildren: this.service.group === 'A' ? #moduleA : #moduleB</code>. Is this possible? If so, is ok to inject services in routes modules? </p>
  
  <p>2 - I could use specific guard for root route and then do a redirect. In that case, I would use a canLoad as I don't want to module event load if the group not match ( [<a href="https://stackoverflow.com/questions/42026045/difference-between-angulars-canload-and-canactivate][1]">Difference between Angular&#39;s canLoad and canActivate?</a>). If so, I would need to identify if current route is the root to apply the redirect.</p>
  
  <p>I have the following code: </p>
  
  <pre><code>const routes: Routes = [
  {
  path: '',
  loadChildren: './moduleOne.module#moduleOne', //the module that will be 
  //loaded will depends on the group of current user.
  canActivate: [AuthGuard]
  },
  </code></pre>
  
  <p>Thank you all!</p>