0
0
Angularframework~20 mins

Defining routes array in Angular - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Angular Routes Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What happens when navigating to '/dashboard'?

Given this Angular routes array, what component will display when the user navigates to '/dashboard'?

Angular
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 }
];
AHomeComponent is displayed
BDashboardComponent is displayed
CBoth HomeComponent and DashboardComponent are displayed
DNo component is displayed, navigation fails
Attempts:
2 left
💡 Hint

Look at the path that matches '/dashboard' in the routes array.

📝 Syntax
intermediate
2:00remaining
Which routes array syntax is correct?

Which of the following Angular routes array definitions is syntactically valid?

Aconst routes: Routes = [{ path: '', component: 'HomeComponent' }];
Bconst routes = [{ path: '', component HomeComponent }];
Cconst routes: Routes = [{ path: '', component: HomeComponent }];
Dconst routes: Routes = [{ path: '', component: HomeComponent }]
Attempts:
2 left
💡 Hint

Check for correct TypeScript syntax and object property assignments.

🔧 Debug
advanced
2:30remaining
Why does this route configuration cause a runtime error?

Consider this routes array. Why will navigating to '/profile' cause an error?

Angular
import { Routes } from '@angular/router';
import { ProfileComponent } from './profile.component';

export const routes: Routes = [
  { path: 'profile', component: ProfileComponent, children: [
    { path: '', component: ProfileComponent }
  ]}
];
AIt works fine without errors
BIt causes a syntax error due to missing comma
CIt causes a runtime error because children array is empty
DIt causes infinite recursion because ProfileComponent is loaded inside itself as a child route
Attempts:
2 left
💡 Hint

Think about what happens when a component loads itself as a child route.

state_output
advanced
2:00remaining
How many routes are accessible in this array?

Given this routes array, how many distinct routes can a user navigate to?

Angular
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: '' }
];
A3 routes
B2 routes
C4 routes
D5 routes
Attempts:
2 left
💡 Hint

Count only distinct paths that load components, ignoring wildcard redirects as separate routes.

🧠 Conceptual
expert
2:30remaining
What is the effect of this routes array on navigation?

Analyze this Angular routes array. What happens when a user navigates to '/settings'?

Angular
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 }
];
ASettingsComponent is displayed
BBoth SettingsComponent and NotFoundComponent are displayed
CNavigation fails with an error
DNotFoundComponent is displayed
Attempts:
2 left
💡 Hint

Consider how Angular matches routes and the role of the wildcard '**' route.