Saturday, July 11, 2020

Angular 6 Routing Simple Working Example

Angular 6 Routing Simple Working Example - The Rich Post


Hello to all, welcome to  In this post, I am going to tell, Angular 6 Routing Simple Working Example.

Here is the working picture:


Here is the code and need to add the Angular 6 application for routing:

1. Very first, please make two new component for routing process and please run below commands for creating new angular components into your terminal:
ng g component aboutus

ng g component contantus
 You can see below new folders, after run above command:


2. After that, Here is the code for app.module.ts file:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { Routes, RouterModule } from '@angular/router';
import { AboutusComponent } from './aboutus/aboutus.component';
import { ContantusComponent } from './contantus/contantus.component';

const appRoutes: Routes = [
    { path: 'aboutus', component: AboutusComponent },
  { path: 'contactus', component: ContantusComponent }

  declarations: [
  imports: [
      { enableTracing: true } // <-- debugging purposes only
  entryComponents: [AppComponent],
  providers: [],
  bootstrap: [AppComponent]
export class AppModule { }


3. After that, here is the code for app.component.html file:
<div class="jumbotron text-center">
  <h1>Angular 6 Routing Example</h1>
<nav class="navbar navbar-expand-sm bg-light">
  <ul class="nav nav-pills">
    <li class="nav-item"><a class="nav-link" routerLink="/aboutus">About Us</a></li>
  <li class="nav-item"><a class="nav-link" routerLink="/contactus">Contact Us</a></li>

<div class="container-fluid">

 And that is it and this is very easy and everyone can do this. 

If have any query related to this post, then please so ask questions or comment below.

Ajay Malhotra
the authorAjay Malhotra
Hello to all. Welcome to Myself Ajay Malhotra and I am freelance full stack developer. I love coding. I know Wordpress, Core php, Angularjs, Angular 2, Angular 6, Angular 7, Angular 8, Angular 9, Angular 10 Nodejs, laravel, Codeigniter, Shopify, Squarespace, Jquery, Google Map Api, Vuejs, Reactjs, Bigcommerce etc.


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.