Given this Angular RouterModule configuration, what component will display when the URL is '/dashboard'?
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 {}
Check which route matches the path '/dashboard' exactly.
The route with path 'dashboard' matches the URL '/dashboard' exactly, so DashboardComponent is displayed.
Which option correctly identifies the syntax error in this Angular routing setup?
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 {}
Redirect routes need a pathMatch property to work correctly.
Redirect routes require pathMatch: 'full' to specify how the path is matched. Without it, Angular throws an error.
Consider this route configuration and navigation to '/product/42'. What will activatedRoute.snapshot.params.id contain?
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; }
Route parameters are always strings in Angular.
Route parameters are parsed as strings, so id will be the string "42".
Given this RouterModule configuration, why does the lazy-loaded module fail to load?
const routes = [ { path: 'admin', loadChildren: () => import('./admin/admin.module').then(m => m.AdminModule) } ]; @NgModule({ imports: [RouterModule.forRoot(routes)], exports: [RouterModule] }) export class AppRoutingModule {}
Check the import path and file existence for lazy loading.
If the import path is wrong or the file does not exist, the lazy-loaded module cannot be loaded.
In Angular RouterModule, what happens when a redirect route uses pathMatch: "prefix" instead of "full"?
const routes = [ { path: '', redirectTo: 'home', pathMatch: 'prefix' }, { path: 'home', component: HomeComponent } ];
Think about what matching the prefix '' means for all URLs.
Using pathMatch: 'prefix' with an empty path matches every URL, causing the redirect to trigger repeatedly and create an infinite loop.