Bird
0
0

Which is the best way to configure the main app routing to achieve this and ensure accessibility and performance?

hard🚀 Application Q15 of 15
Angular - Routing
You want to lazy load a feature module ProfileModule only when the user navigates to /profile. The module has child routes. Which is the best way to configure the main app routing to achieve this and ensure accessibility and performance?
A{ path: 'profile', loadChildren: () => import('./profile/profile.module').then(m => m.ProfileModule), canActivate: [AuthGuard] }
B{ path: 'profile', component: ProfileModule }
C{ path: 'profile', loadChildren: () => import('./profile/profile.module').then(m => m.ProfileModule) }
D{ path: 'profile', loadChildren: './profile/profile.module#ProfileModule' }
Step-by-Step Solution
Solution:
  1. Step 1: Identify modern lazy loading syntax

    The correct syntax uses dynamic import with an arrow function returning a promise: loadChildren: () => import('./profile/profile.module').then(m => m.ProfileModule).
  2. Step 2: Consider best practices for accessibility and performance

    For protected features like a user profile, adding canActivate: [AuthGuard] ensures secure access while lazy loading maintains performance.
  3. Step 3: Eliminate incorrect configurations

    Using component property fails for modules with child routes. String syntax like './profile/profile.module#ProfileModule' is deprecated.
  4. Final Answer:

    { path: 'profile', loadChildren: () => import('./profile/profile.module').then(m => m.ProfileModule), canActivate: [AuthGuard] } -> Option A
  5. Quick Check:

    Lazy load with guard for best practice [OK]
Quick Trick: Lazy load with import and add guards for security [OK]
Common Mistakes:
MISTAKES
  • Using component instead of loadChildren for modules
  • Using deprecated string syntax
  • Forgetting route guards for protected routes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes