Load a module immediately when the app starts

25 views
Skip to first unread message

Robert Gomez

unread,
Apr 4, 2020, 11:22:17 PM4/4/20
to Angular and AngularJS discussion
Hi,

I have an AuthModule with my components, imports, exports, routing, etc....
I would like to load it immediately when the app starts to have all its routing available since the beggining, in other words, I don't want to load this module lazily.

I have found that if I keep this module imported in the imports of the app.module.ts, all routes of my AuthModule are working as expected.

The question is:
  1. This is the correct approach?
  2. Should I use a custom PreloadingStrategy that is mentioned in a lot of blogs out there? (and why)
Both ways works, but, what's the difference? what is the correct way to do this?

bastien lemaire

unread,
Apr 7, 2020, 5:15:44 AM4/7/20
to Angular and AngularJS discussion
Hey Robert, this is the right approach but that means the routes defined in authModule will not be nested within routes defined in AppModule

Sander Elias

unread,
Apr 7, 2020, 5:16:11 AM4/7/20
to Angular and AngularJS discussion
Hi Robbert,

Then don't load is lazy, just use it as a normal module.

Regards
Sander

Robert Gomez

unread,
Apr 7, 2020, 8:58:19 AM4/7/20
to Angular and AngularJS discussion
On Tuesday, April 7, 2020 at 5:15:44 AM UTC-4, bastien lemaire wrote:
Hey Robert, this is the right approach but that means the routes defined in authModule will not be nested within routes defined in AppModule


Hi, thanks for answering me back. Do you think that will have an impact on performance or something? Should my AuthModule routes be nested within routes defined in app.routing? 

Sander Elias

unread,
Apr 7, 2020, 2:55:46 PM4/7/20
to Angular and AngularJS discussion
Hi Robert,

Your initial payload will be bigger, but all things auth will load from the get-go without slowdown. So it is up to you what you prefer.

Regards
Sander
Reply all
Reply to author
Forward
0 new messages