0
0
Angularframework~20 mins

Child routes and nested routing in Angular - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Nested Routing Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What will be rendered by the nested router-outlet?

Given the following Angular route configuration and component setup, what will be displayed inside the nested <router-outlet> when navigating to /dashboard/stats?

Angular
const routes = [
  { path: 'dashboard', component: DashboardComponent, children: [
    { path: 'stats', component: StatsComponent },
    { path: 'reports', component: ReportsComponent }
  ]}
];

// DashboardComponent template:
// <h1>Dashboard</h1>
// <router-outlet></router-outlet>
A<app-stats></app-stats>
B<h1>Dashboard</h1><app-reports></app-reports>
C<h1>Dashboard</h1>
D<h1>Dashboard</h1><app-stats></app-stats>
Attempts:
2 left
💡 Hint

Remember that child routes render inside the parent's <router-outlet>.

📝 Syntax
intermediate
2:00remaining
Identify the correct child route syntax

Which of the following Angular route configurations correctly defines a child route for profile under user?

Aconst routes = [{ path: 'user', children: [{ path: 'profile', component: ProfileComponent }] }];
Bconst routes = [{ path: 'user/profile', component: ProfileComponent, children: [{ path: '', component: UserComponent }] }];
Cconst routes = [{ path: 'user', component: UserComponent, children: [{ path: 'profile', component: ProfileComponent }] }];
Dconst routes = [{ path: 'user', component: UserComponent }, { path: 'profile', component: ProfileComponent, children: [] }];
Attempts:
2 left
💡 Hint

Child routes must be inside the children array of the parent route and the parent must have a component.

🔧 Debug
advanced
2:00remaining
Why does the nested route not render?

Consider this Angular route setup:

const routes = [
  { path: 'home', component: HomeComponent, children: [
    { path: 'details', component: DetailsComponent }
  ]}
];

The HomeComponent template is:

<h2>Home</h2>
<div>Welcome!</div>

When navigating to /home/details, the DetailsComponent does not appear. What is the most likely cause?

AThe <code>HomeComponent</code> template is missing a <code>&lt;router-outlet&gt;</code> for child routes.
BThe route path 'details' should be defined at the root level, not as a child.
CThe <code>DetailsComponent</code> is not declared in the module.
DThe URL should be '/details/home' to match the route.
Attempts:
2 left
💡 Hint

Child routes render inside the parent's <router-outlet>.

state_output
advanced
2:00remaining
What is the URL and rendered output after navigation?

Given this Angular route configuration:

const routes = [
  { path: '', component: MainComponent, children: [
    { path: '', component: WelcomeComponent },
    { path: 'about', component: AboutComponent }
  ]}
];

And the MainComponent template:

<nav>
  <a routerLink="">Welcome</a>
  <a routerLink="about">About</a>
</nav>
<router-outlet></router-outlet>

What will be the URL and displayed content after clicking the 'About' link?

AURL: '/about'; Content: Only AboutComponent without MainComponent
BURL: '/about'; Content: MainComponent with AboutComponent inside router-outlet
CURL: '/'; Content: WelcomeComponent only
DURL: '/about'; Content: MainComponent with WelcomeComponent inside router-outlet
Attempts:
2 left
💡 Hint

Child routes render inside the parent's <router-outlet> and the parent component remains visible.

🧠 Conceptual
expert
2:00remaining
Which statement about nested routing is TRUE?

Choose the correct statement about Angular child routes and nested routing.

AChild routes require the parent component to have a <code>&lt;router-outlet&gt;</code> to render nested components.
BNested routes can only be defined up to two levels deep in Angular routing.
CChild routes automatically inherit all parent route guards without additional configuration.
DChild routes replace the parent component in the DOM when activated.
Attempts:
2 left
💡 Hint

Think about how Angular renders nested routes inside parent components.