Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

116
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda