Search code examples
angularangular2-routingangular4-router

CanLoad guard for AppModule


i have an angular application created using angular-cli. I am able to use CanLoad guard for my modules. In my CanLoad check, I check if the user is logged in or not.

Can i use a CanLoad for AppModule also? Basically do not load even the AppModule if the user is not authenticated.

Reason for this question :
All the content of the website has to be auth protected. So i am trying to reduce the payload before the user authenticates.


Solution

  • As @trichetriche answered, if you put a guard on app module the user will not be able to even login only if app module was being bootstrapped by main.ts.

    You can bootstrap another module, login module for example, and from it lazy loads app module using CanLoad. I've never seem a pattern like this, but it's possible.