NG.V · Angular 22 practice question
In Angular routing, when setting up nested routes, what is the fundamental difference in how the `router-outlet` directive must be placed in the template hierarchy to achieve the desired rendering behavior? Consider the following route configuration structure:
const routes: Routes = [
{
path: 'parent',
component: ParentComponent,
children: [
{ path: 'child-a', component: ChildAComponent },
{ path: 'child-b', component: ChildBComponent }
]
}
];
Check answer and explanation
Correct answer: The `router-outlet` for the parent route must be placed *inside* the `ParentComponent`'s template to render `ChildAComponent` or `ChildBComponent`.
Explanation
For nested routing to work, the component responsible for the parent route (`ParentComponent` in this case) must contain a `<router-outlet></router-outlet>`. This outlet acts as the placeholder where the components corresponding to the child routes (`ChildAComponent` or `ChildBComponent`) will be dynamically loaded and displayed when the URL matches the child path segment.
Common trap
Option B incorrectly suggests children need their own outlets, which is only necessary for deeper nesting, but the immediate requirement for the parent view to host its children is its own outlet. Option D is incorrect because while the parent renders, the child will *also* fail to render without the outlet.
Source: Routing Overview - Angular Docs (https://angular.dev/guide/routing)
Checked against the cited text on 2026-11-27.