Angular2 Routing

General Description:-

 

 Angular Routing is the process of moving packets across a network from one host to another. It is usually performed by dedicated devices called routersAngular  Routing performs navigation across one page to another page when user click on any link, just like single page application.Packets are the fundamental unit of information transport in all modern computer networks,

 

Routing in Angular:-

 

 Routing performs navigation across one page to another page when user click on any link, just like single page application.

 

Now am going to explain to step by step:

 

Step-1:

Now I’m going to create 3(three) components namely  Home, About, Services as shown below .

 

For that am using command –

ng generate component home :

It will creates HOME component with the name of home and contains 4 files(mentioned in image). After that it will update app.module.ts file.

ng generate component about :AngularJS Routing training in hyderabad

ng generate component contact :

AngularJS Training in Hyderabad

In Home component

I’m adding some information in home.component.html file whereas the same information will be added in about component about.component.html  and contact component contact .component.html  .

 If you want to see all component information you can add like this in

Home.component.html file

<app-home></app-home>

<app-home></app-home>

<app-home></app-home>

But this not good method we need write to routing

Step-2: app. component. Html file

Am going to add header information like.

 Angular training in hyderabad

Step-3 app. Module’s

In this file we need to import some modules  Router Module & Routes from @angular/router.

Angular2 routing

Step-4app. Module.ts

After import that RouterModule & Routes then we need to add

const routes:Routes=[

{….},{….},{….}];

Angularjs training in hyderabad

Step-5 app. Module.ts

Next declaration section in (imports) we need to add 

Angular 2 training

Step-6 app. component.html

For navigation we need to add

<router-outlet></router-outlet>

 

Throught like Navigation we need to add routerLink=” /home ”

Angular training in hyderabad

In url:-Localhost:4200/home

 Angular Routing

In url:-Localhost:4200/about

 Angular for beginners

In url:-Localhost:4200/contact

 AngularJS training in hyderabad

 

 

 

Please follow and like us:
500

Leave a Reply

Your email address will not be published. Required fields are marked *