Angular - RoutingYou 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' }Check Answer
Step-by-Step SolutionSolution:Step 1: Understand redirectTo usageTo redirect from '' path, use redirectTo with full path and specify pathMatch as 'full' to match exact empty path.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.Final Answer:{ path: '', redirectTo: '/home', pathMatch: 'full' } -> Option AQuick Check:Redirect empty path with pathMatch 'full' [OK]Quick Trick: Use pathMatch: 'full' when redirecting empty path [OK]Common Mistakes:MISTAKESOmitting pathMatch propertyCombining component with redirectToUsing pathMatch: 'prefix' for empty path redirect
Master "Routing" in Angular9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallPerf
More Angular Quizzes HTTP Client - HttpClientModule setup - Quiz 12easy Reactive Forms - FormGroup for grouping controls - Quiz 5medium Reactive Forms - Custom validators - Quiz 11easy Reactive Forms - Form state tracking (dirty, touched, valid) - Quiz 8hard Reactive Forms - Form state tracking (dirty, touched, valid) - Quiz 6medium Routing - RouterLink for navigation - Quiz 2easy Routing - Query parameters and fragments - Quiz 4medium RxJS Operators - switchMap for flattening - Quiz 5medium RxJS and Observables Fundamentals - Observable vs Promise mental model - Quiz 2easy Services and Dependency Injection - Creating a service with CLI - Quiz 3easy