How to enable routing and navigation between component pages in Angular 8 ? Last Updated : 29 Jul, 2024 Comments Improve Suggest changes Like Article Like Report The task is to enable routing between angular components by making their routes when a user clicks the link, it will be navigated to page link corresponding to the required component.Let us know what is routing in AngularAngular 8 routing:The Angular 8 Router helps to navigate between pages that are being triggered by the user's actions. The navigation happens when the user clicks on the link or enter the URL from the browser address bar. The link can contain the reference to the router on which the user will be directed. We can also pass other parameters with a link through angular routing.Approach:Create an Angular app. syntax:ng new app_nameFor routing you will need components, here we have made two components (home and dash) to display home page and dashboard. syntax:ng g c component_nameIn app.module.ts, import RouterModule from @angular/router. syntax:import { RouterModule } from '@angular/router';Then in imports of app.module.ts define the paths. imports: [ BrowserModule, AppRoutingModule, RouterModule.forRoot([ { path: 'home', component: HomeComponent }, { path: 'dash', component:DashComponent } ]) ],Now for HTML part, define the HTML for app.component.html. In link, define routerLink's path as the component name.<a routerLink="/home">Home </a><br><a routerLink="/dash">dashboard</a>Apply router-outlet for your application in app.component.html.The routed views render in the <router-outlet><router-outlet></router-outlet>Now just define HTML for home.component.html and dash.component.html file.Your angular web-app is ready.Code Implementation:app.module.ts: javascript import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { RouterModule } from '@angular/router'; import { AppRoutingModule } from './app-routing.module'; import { AppComponent } from './app.component'; import { HomeComponent } from './home/home.component'; import { DashComponent } from './dash/dash.component'; @NgModule({ declarations: [ AppComponent, HomeComponent, DashComponent ], imports: [ BrowserModule, AppRoutingModule, RouterModule.forRoot([ { path: 'home', component: HomeComponent }, { path: 'dash', component:DashComponent } ]) ], providers: [], bootstrap: [AppComponent] }) export class AppModule { } app.component.html html <a routerLink="/home">Home </a><br> <a routerLink="/dash">dashboard</a> <router-outlet></router-outlet> home.component.html html <h1>GeeksforGeeks</h1> dash.component.html html <h1>Hey GEEKS! Welcome to Dashboard</h1> Output:Run the development server and click on the links: Comment More infoAdvertise with us Next Article How to enable routing and navigation between component pages in Angular 8 ? taran910 Follow Improve Article Tags : Web Technologies AngularJS AngularJS-Misc Similar Reads How To Prevent Scrolling With Navigation in Angular Component? When navigating between routes in an Angular application, the browser's scroll position is often reset to the top of the page. This can be frustrating for users who want to maintain their scroll position between route changes. In this article, we'll explore how to prevent scrolling with navigation i 10 min read Difference between Link and Navigate Component in React Router In this article, we'll delve into the intricacies of two fundamental components within the widely acclaimed React Router Dom Library a Link and Navigate. As the backbone of many react applications, these components play pivotal roles in facilitating seamless navigation and routing. We'll explore the 4 min read How to display loading screen when navigating between routes using Angular? In this post, we will see how to display a loading screen when navigating from one component to another. When the user navigates through routes, the app may communicate with the backend to load some useful data, and it may produce some delay. At that time, if the user doesn't see anything on the scr 5 min read Introduction To Components And Templates in Angular Angular is a powerful framework for building dynamic, single-page web applications. One of the core concepts that make Angular so effective is its use of components and templates. Components and templates are the building blocks of any Angular application, allowing developers to create reusable, mai 6 min read What is Routing and Nested Routing in Angular 9/8 ? In this article, we will learn the routing & nested routing concept in Angular. We will implement the concept to establish routing between different components by making their routes when a user clicks the link, it will be navigated to a page link corresponding to the required component. Let's u 5 min read A Complete Guide To Angular Routing Angular Routing is a technology to build single-page applications that provide multi-page services at a single port. It enables seamless navigation and loading of the different pages. When an Angular app is started then the whole component is only loaded at once and dynamically reloads the requested 6 min read How does React Router handle navigation in a React application? React Router is a standard library for routing in React. It enables the navigation among views of various components in a React Application, allows changing the browser URL, and keeps the UI in sync with the URL. Let us create a simple application to React to understand how the React Router works Re 3 min read Mastering React Routing: Learn Navigation and Routing in React Apps React Routing is a technique used to handle navigation within a React application. It enables users to move between different views, pages, or components without refreshing the entire page, which is a key feature of Single Page Applications (SPAs).In this article, we will explore the essential conce 6 min read Establish communication between sibling components in Angular 11 In this article, we will see how we can pass data between sibling components on client machine. In Angular, we divide our web page into multiple components and the relation among these component forms a tree like structure. A component may have a parent and multiple children. That said, it can also 5 min read How to create module with Routing in Angular 9 ? Angular applications are modular, and NgModules is Angular's own modular architecture. NgModules are containers for closely integrated application domains, workflows, or feature sets that comprise cohesive code blocks. Their scope is governed by the NgModule they include, and they can contain compon 4 min read Like