What does RouterModule do?
RouterModule is an Angular module that includes everything needed for routing to work.
It does several key things:
- Registers the routes passed to
RouterModule.forRoot()orRouterModule.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.
- Provides the
Routerservice - 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 readyPremium
A concise answer to help you respond confidently on this topic during an interview.