Routing Questions with Answers

18 practice questions on Routing (Angular) with answers and step-by-step solutions. Try 10 samples below, then practise all 18 free in the AptiNest app.

Sample questions

Question 1Easy

Which directive creates a navigation link without a full page reload?

  1. href only
  2. routerLink
  3. ngLink
  4. navigateTo

Answer: B. routerLink

Explanation

routerLink tells the Router to navigate, updating the URL and view without reloading.

Step-by-step solution

  1. RouterLink is a directive used in Angular for navigation.
  2. It updates the URL and view without reloading the page.
  3. Other options like href or navigateTo do not provide this functionality.
  4. NgLink is not a standard directive for routing in Angular.
  5. The correct answer is routerLink.

Why the other options are wrong

  • A. href causes a full page reload when clicked, so it does not give client-side navigation.
  • C. ngLink is not a standard Angular routing directive, so it is not the answer.
  • D. navigateTo is not a built-in Angular directive; navigation uses routerLink or the Router service.

Tip: Use routerLink for smooth navigation in Angular apps without full reloads.

Question 2Easy

Which directive renders the component matched by the current route?

  1. <router-outlet>
  2. <ng-content>
  3. <router-link>
  4. <ng-view>

Answer: A. <router-outlet>

Explanation

router-outlet is the placeholder where the router displays the routed component.

Step-by-step solution

  1. The router must show the matched component somewhere in the page.
  2. Router-outlet is the placeholder where the router displays that component.
  3. The correct answer is A (<router-outlet>).

Why the other options are wrong

  • B. Ng-content is for content projection, not routing.
  • C. Router-link creates links; it does not display components.
  • D. Ng-view is not an Angular directive.

Tip: Place router-outlet in your app shell where pages should appear.

Question 3Easy

Which directive in a template marks where the routed component is displayed?

  1. <ng-content> which projects content
  2. <router-outlet>
  3. <router-link> which creates a link
  4. <ng-view>

Answer: B. <router-outlet>

Explanation

The outlet renders the component for the active route.

Step-by-step solution

  1. Placeholder for routed views.

Why the other options are wrong

  • A. ng-content projects content into a component; it does not show routes.
  • C. RouterLink is for links.
  • D. ng-view is AngularJS; Angular uses router-outlet instead.

Question 4Medium

How do you define a route with a path parameter id?

  1. { path: 'user/:id', component: UserComponent }
  2. { path: 'user/{id}', component: UserComponent }
  3. { path: 'user?id', component: UserComponent }
  4. { path: 'user#id', component: UserComponent }

Answer: A. { path: 'user/:id', component: UserComponent }

Explanation

A colon prefix declares a route parameter.

Step-by-step solution

  1. Colon syntax.

Why the other options are wrong

  • B. Curly braces are not route parameter syntax; use a colon.
  • C. A question mark does not declare a route parameter in Angular.
  • D. A hash does not declare a route parameter in Angular.

Question 5Medium

How can a component read a route parameter reactively as it changes?

  1. Read window.location only once in the constructor
  2. Add an @Input decorator directly on the Router service
  3. Call Router.id() whenever a link is clicked on the page
  4. Subscribe to ActivatedRoute.paramMap

Answer: D. Subscribe to ActivatedRoute.paramMap

Explanation

paramMap emits whenever the parameters change while the same component instance is reused.

Step-by-step solution

  1. Subscribe to ActivatedRoute.paramMap in the component's constructor.
  2. ParamMap emits a new value each time route parameters change.
  3. This allows the component to reactively update based on parameter changes.
  4. No need for extra code to track parameter updates manually.
  5. The component stays in sync with route parameters automatically.
  6. Final answer: Subscribe to ActivatedRoute.paramMap.

Why the other options are wrong

  • A. Reading window.location once does not update when the route parameter changes.
  • B. @Input belongs on component properties, not on the Router service, so this cannot work.
  • C. Router.id() is not a real method; the route parameter is read from ActivatedRoute.

Tip: Use paramMap subscription for reactive route parameter updates in Angular.

Question 6Medium

Which service reads the current route's parameters?

  1. Router.params exposed on the Router service
  2. ActivatedRoute
  3. HttpClient for network calls
  4. FormBuilder

Answer: B. ActivatedRoute

Explanation

ActivatedRoute exposes params and snapshot.

Step-by-step solution

  1. Need route info.

Why the other options are wrong

  • A. The Router service has no params property for route parameters.
  • C. HttpClient is for HTTP.
  • D. FormBuilder builds forms.

Question 7Medium

What does a route guard such as canActivate decide?

  1. Whether a component is destroyed once the user leaves the page
  2. How HTTP requests are retried
  3. Whether navigation to the route is allowed
  4. Which pipe to use

Answer: C. Whether navigation to the route is allowed

Explanation

Guards return true/false or a UrlTree.

Step-by-step solution

  1. Check before activation.

Why the other options are wrong

  • A. Destroy is canDeactivate-like.
  • B. Route guards control navigation, not HTTP request retries.
  • D. Route guards have nothing to do with choosing a pipe.

Question 8Medium

Which route config entry matches any unknown URL, usually shown as a 404 page?

  1. { path: '*', redirectTo: '' }
  2. { path: '', component: NotFoundComponent }
  3. { path: '**', component: NotFoundComponent }
  4. { path: '404**', component: NotFoundComponent }

Answer: C. { path: '**', component: NotFoundComponent }

Explanation

The wildcard ** matches everything, so it must be placed last in the route list.

Step-by-step solution

  1. The question asks for a catch-all route for unknown URLs.
  2. The path ** matches any URL.
  3. It must be last in the list so it does not catch earlier routes. The correct answer is C ({ path: '**', component: NotFoundComponent }).

Why the other options are wrong

  • A. A single * is not the wildcard, and a redirect sends users elsewhere; it does not show a 404 page.
  • B. An empty path matches only the root URL.
  • D. 404** is a literal path, not a wildcard for all URLs.

Tip: Put the ** route last in the route list.

Question 9Hard

What does { path: '**', component: NotFoundComponent } placed first in the routes array do?

  1. Only matches unknown routes regardless of position
  2. Matches every URL and hides all later routes
  3. Is ignored
  4. Throws at compile time

Answer: B. Matches every URL and hides all later routes

Explanation

Routes are matched in order and the wildcard matches everything, so it belongs last.

Step-by-step solution

  1. First match wins.

Why the other options are wrong

  • A. Position matters: a first wildcard catches every URL before later routes.
  • C. The route is not ignored; it matches every URL first.
  • D. Routes are checked at runtime, and this placement compiles fine.

Question 10Hard

What is lazy loading of routes?

  1. Loading a route lazily, after the user has scrolled, only on mobile devices
  2. Loading a route's code only when first visited, shrinking the initial bundle
  3. Delaying API calls until the browser is idle, for every component
  4. Rendering routes without templates until the first click event arrives

Answer: B. Loading a route's code only when first visited, shrinking the initial bundle

Explanation

Lazy loading uses loadChildren or loadComponent with a dynamic import so code is fetched on demand.

Step-by-step solution

  1. Lazy loading loads route code only when first visited.
  2. This shrinks the initial bundle size.
  3. It uses loadChildren or loadComponent for dynamic imports.
  4. Code is fetched on demand, improving performance.
  5. Final answer: Loading a route's code only when first visited, shrinking the initial bundle.

Why the other options are wrong

  • A. Lazy loading is not tied to scrolling or mobile devices; it is about loading route code on first visit.
  • C. Delaying API calls until idle is a different technique; lazy routes load code, not data.
  • D. Routes do not render without templates until a click; lazy loading loads route code on first visit.

Tip: Use lazy loading to split code into smaller chunks for faster initial load.

Practise all 18 questions free

The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.

Open this topic in the app →

Related topics

See all Angular topics · All topics