Skip to main content

What does RouterModule do?

RouterModule is an Angular module that includes everything needed for routing to work.

It does several key things:

  1. Registers the routes passed to RouterModule.forRoot() or RouterModule.forChild().
typescript
RouterModule.forRoot(routes)

This connects the list of routes to Angular's routing system. 2. Adds routing directives:

  • <router-outlet> - the place in the template where the component for the current route is inserted;
  • routerLink, routerLinkActive, and others - for navigating through links.
  1. Provides the Router service - for programmatic navigation (router.navigate()), access to the current route, parameters, and so on.

Without RouterModule, routing simply does not work - Angular does not know which components to show when navigating to a URL.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.