Angular Router is a powerful JavaScript router built and maintained by the Angular core team. It can be imported from the @angular/router package. Angular routing enables navigation from one view to another without a page reload. In Angular 21, routing is configured using provideRouter() in app.config.ts instead of importing RouterModule in an NgModule.
Routing and Navigation Steps
Routing & navigation can be easily enable by using below steps-
Step 1
Add base path to src/index.html file
Example
<base href="/">
Step 2
In Angular 21, configure routes using provideRouter() in app.config.ts and define routes in app.routes.ts. No NgModule needed.
Add RouterOutlet, which is a directive from the router library that is used like a placeholder for all the component. RouterOutlet it is a spot in the template where the router should display the components for that outlet.
Example
<!-- Routed components will be display here -->
<router-outlet></router-outlet>