0
0
Angularframework~20 mins

RouterModule configuration in Angular - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
RouterModule Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What happens when you navigate to '/dashboard' with this RouterModule setup?

Given this Angular RouterModule configuration, what component will display when the URL is '/dashboard'?

Angular
const routes = [
  { path: '', redirectTo: 'home', pathMatch: 'full' },
  { path: 'home', component: HomeComponent },
  { path: 'dashboard', component: DashboardComponent },
  { path: '**', component: NotFoundComponent }
];

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})
export class AppRoutingModule {}
ADashboardComponent is displayed
BNo component is displayed, navigation fails
CNotFoundComponent is displayed
DHomeComponent is displayed
Attempts:
2 left
💡 Hint

Check which route matches the path '/dashboard' exactly.

📝 Syntax
intermediate
2:00remaining
Identify the syntax error in this RouterModule configuration

Which option correctly identifies the syntax error in this Angular routing setup?

Angular
const routes = [
  { path: '', redirectTo: 'home', pathMatch: 'full' },
  { path: 'home', component: HomeComponent },
  { path: 'about', component: AboutComponent }
];

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})
export class AppRoutingModule {}
AMissing 'pathMatch: "full"' in redirect route causes error
BComponent names must be strings, not identifiers
CRouterModule.forRoot() requires a second argument for options
DRoutes array must be declared inside the @NgModule decorator
Attempts:
2 left
💡 Hint

Redirect routes need a pathMatch property to work correctly.

state_output
advanced
2:00remaining
What is the value of 'activatedRoute.snapshot.params.id' after navigation?

Consider this route configuration and navigation to '/product/42'. What will activatedRoute.snapshot.params.id contain?

Angular
const routes = [
  { path: 'product/:id', component: ProductComponent }
];

// Navigation happens to '/product/42'

// Inside ProductComponent constructor:
constructor(private activatedRoute: ActivatedRoute) {
  const id = this.activatedRoute.snapshot.params.id;
}
Anull
B"42" (string)
Cundefined
D42 (number)
Attempts:
2 left
💡 Hint

Route parameters are always strings in Angular.

🔧 Debug
advanced
2:00remaining
Why does this lazy-loaded module fail to load?

Given this RouterModule configuration, why does the lazy-loaded module fail to load?

Angular
const routes = [
  { path: 'admin', loadChildren: () => import('./admin/admin.module').then(m => m.AdminModule) }
];

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})
export class AppRoutingModule {}
AloadChildren must be a string, not a function
BAdminModule is missing the @NgModule decorator
CThe import path './admin/admin.module' is incorrect or file missing
DRouterModule.forRoot() cannot be used with lazy loading
Attempts:
2 left
💡 Hint

Check the import path and file existence for lazy loading.

🧠 Conceptual
expert
2:00remaining
What is the effect of 'pathMatch: "prefix"' in a redirect route?

In Angular RouterModule, what happens when a redirect route uses pathMatch: "prefix" instead of "full"?

Angular
const routes = [
  { path: '', redirectTo: 'home', pathMatch: 'prefix' },
  { path: 'home', component: HomeComponent }
];
ARedirect is ignored and the empty path loads no component
BRedirect only triggers when the full URL matches '', working as expected
CRedirect triggers only for URLs starting with 'home'
DRedirect triggers for every URL starting with '', causing an infinite redirect loop
Attempts:
2 left
💡 Hint

Think about what matching the prefix '' means for all URLs.