Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

119
Views
LazyLoading and config angular NgModule

I have a module 'DevicePreview' that have some routes and can be displayed both from root and from inside another module 'Content'.

When called from root DevicePreview has routes /a, /b and /c available, when called from Content it has /a, /b and /z.

Right now I'm exporting 2 arrays of routes like this (names are faked):

export const DEVICE_ROOT_ROUTES: Routes = [
  {
    path: 'a',
    component: DeviceAComponent
  },  {
    path: 'b',
    component: DeviceBComponent
  },  {
    path: 'c',
    component: DeviceCComponent
  }
];

export const DEVICE_CONTENT_ROUTES: Routes = [
  {
    path: 'a',
    component: DeviceAComponent
  },  {
    path: 'b',
    component: DeviceBComponent
  },  {
    path: 'z',
    component: DeviceZComponent
  }
];

Now I want to move this to lazy loaded module. AFAIK to lazy load modules I have to do this:

 {
    path: 'device',
    loadChildren: 'app/+device/device.module#DeviceModule'
  }

As I don't want to enable Z in root nor C in Component and neither generating 2 different modules I'm thinking of configuring DeviceModule when loading through a .forChild(options)

How could I call forChild when lazy loading? I may consider other approaches too.

Thanks!

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

I'm not sure i follow what you are trying to accomplish but, have you heard of the AuthGuard? You can use for example to verify if a route can be accessed by using canActivate.

Ex:

{ 
        path: 'device', 
        loadChildren: 'app/+device/device.module#DeviceModule', 
        canActivate: [AuthGuard] 
},

And then:

@Injectable()
export class AuthGuard implements CanActivate {

constructor() {}

 canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) 
 {
   //Your logic here to check if for example the module trying
   //to access the route is actually allowed to do that

 }
}

docs: https://angular.io/api/router/CanActivate

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!