Given this Angular routes array, what component will display when the user navigates to '/dashboard'?
import { Routes } from '@angular/router'; import { HomeComponent } from './home.component'; import { DashboardComponent } from './dashboard.component'; export const routes: Routes = [ { path: '', component: HomeComponent }, { path: 'dashboard', component: DashboardComponent } ];
Look at the path that matches '/dashboard' in the routes array.
The route with path 'dashboard' maps to DashboardComponent, so navigating to '/dashboard' shows that component.
Which of the following Angular routes array definitions is syntactically valid?
Check for correct TypeScript syntax and object property assignments.
Option C correctly declares routes with type Routes and assigns component as a class reference. Option C misses colon after component. Option C uses a string instead of a component class. Option C misses closing bracket.
Consider this routes array. Why will navigating to '/profile' cause an error?
import { Routes } from '@angular/router'; import { ProfileComponent } from './profile.component'; export const routes: Routes = [ { path: 'profile', component: ProfileComponent, children: [ { path: '', component: ProfileComponent } ]} ];
Think about what happens when a component loads itself as a child route.
Loading ProfileComponent inside its own children causes infinite recursion and runtime errors.
Given this routes array, how many distinct routes can a user navigate to?
import { Routes } from '@angular/router'; import { HomeComponent } from './home.component'; import { AboutComponent } from './about.component'; import { ContactComponent } from './contact.component'; export const routes: Routes = [ { path: '', component: HomeComponent }, { path: 'about', component: AboutComponent }, { path: 'contact', component: ContactComponent }, { path: '**', redirectTo: '' } ];
Count only distinct paths that load components, ignoring wildcard redirects as separate routes.
There are three distinct routes: '', 'about', and 'contact'. The wildcard '**' redirects to '', so it does not add a new route.
Analyze this Angular routes array. What happens when a user navigates to '/settings'?
import { Routes } from '@angular/router'; import { SettingsComponent } from './settings.component'; import { NotFoundComponent } from './not-found.component'; export const routes: Routes = [ { path: 'settings', component: SettingsComponent }, { path: '**', component: NotFoundComponent } ];
Consider how Angular matches routes and the role of the wildcard '**' route.
The route with path 'settings' matches exactly and loads SettingsComponent. The wildcard '**' only matches paths not matched earlier.