Bird
0
0

You want to add a default route that redirects empty path '' to '/home' using RouterModule. Which configuration is correct?

hard🚀 Application Q15 of 15
Angular - Routing
You want to add a default route that redirects empty path '' to '/home' using RouterModule. Which configuration is correct?
A{ path: '', redirectTo: '/home', pathMatch: 'full' }
B{ path: '', redirectTo: 'home' }
C{ path: '', component: HomeComponent, redirectTo: '/home' }
D{ redirectTo: '/home', path: '', pathMatch: 'prefix' }
Step-by-Step Solution
Solution:
  1. Step 1: Understand redirectTo usage

    To redirect from '' path, use redirectTo with full path and specify pathMatch as 'full' to match exact empty path.
  2. Step 2: Check options for correct syntax

    { path: '', redirectTo: '/home', pathMatch: 'full' } correctly uses redirectTo with '/home' and pathMatch: 'full'. { path: '', redirectTo: 'home' } misses pathMatch, C wrongly combines component and redirectTo, D uses 'prefix' which causes partial matching issues.
  3. Final Answer:

    { path: '', redirectTo: '/home', pathMatch: 'full' } -> Option A
  4. Quick Check:

    Redirect empty path with pathMatch 'full' [OK]
Quick Trick: Use pathMatch: 'full' when redirecting empty path [OK]
Common Mistakes:
MISTAKES
  • Omitting pathMatch property
  • Combining component with redirectTo
  • Using pathMatch: 'prefix' for empty path redirect

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes