Bird
0
0

Why does this lazy loading route fail?

medium📝 Debug Q7 of 15
Angular - Performance Optimization
Why does this lazy loading route fail?
{ path: 'user', loadChildren: () => import('./user/user.module').then(m => m.UserModule) }
UserModule is defined but the app throws a runtime error.
AUserModule file path is incorrect
BThe path 'user' must be declared in AppModule imports
CloadChildren must return a component, not a module
DUserModule is missing RouterModule.forChild() imports for its routes
Step-by-Step Solution
Solution:
  1. Step 1: Understand lazy loaded module routing

    Lazy loaded modules must import RouterModule.forChild() with their routes.
  2. Step 2: Identify cause of runtime error

    If UserModule lacks RouterModule.forChild(), routing fails at runtime.
  3. Final Answer:

    UserModule is missing RouterModule.forChild() imports for its routes -> Option D
  4. Quick Check:

    Missing RouterModule.forChild() causes runtime routing error [OK]
Quick Trick: Lazy loaded modules need RouterModule.forChild() for routes [OK]
Common Mistakes:
  • Thinking path must be imported in AppModule
  • Expecting loadChildren to return component
  • Assuming file path is always wrong

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes