Conditionally load modules in Angular 4

1.5k Views Asked by At

Is there any way to load module conditionally or prevent module access in some conditions? I just want to load modules and its subroutes only a specific condition satisfied.

The possible solution I tried till now

  1. Lazy load modules with routing details.
  2. canActivate with auth mechanism service.

Is there any effective way to achieve the same so that.

  1. Common features should not be duplicated.
  2. Module with routing details should be only loaded when in need.

Any help in this regard appreciated TIA.

1

There are 1 best solutions below

0
On BEST ANSWER

check the CanLoad guard.

Interface that a class can implement to be a guard deciding if a children can be loaded.