SlideShare a Scribd company logo
Angular Routers
EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js
Agenda
Why Routers?
1
What is Routers?
2
AngularJS Routers
3
Angular Router
4
Demo
6
Diff b/w AngularJS and
Angular Routers
5
EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js
Why we need Routers?
EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js
Why we need Routers?
Navigation Bar
Side Bar Course List
While navigating through a Single Page Application…
Navbar Component
Side Bar Component Course List Component
EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js
Why we need Routers?
Navigation Bar
Side Bar
Course1
Course3
Course4
Course2
If you reload a part (Course List), it only renders that component without fetching the
whole page (i.e. Navigation Bar & Side Bar) from server
EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js
Why we need Routers?
Navigation Bar
Side Bar
Course 2 Description:
… … …
… … …
Similarly, if you select a course, it only renders Course Description instead of reloading
the whole page
EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js
For a real-time example
EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js
Why we need Routers?
In Gmail inbox while clicking on a mail…
EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js
Why we need Routers?
It only reloads the concerned section, without interfering the rest of the part …
EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js
Without reloading the whole page we can navigate
between components
Thanks to Routers!!!
EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js
What is Router?
EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js
What is Router?
Routing is used for navigating among different components in your SPA (Single Page Application)
Component
1
Component
3
Component
6
Component
4
Component
5
Component
2
EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js
AngularJS Routers
EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js
AngularJS Routers
NgRoute
UI-Router
UI-Router is a contributed module which is overcome the problems of ngRoute.
Mainly Nested/Complex views.
ngRoute is a angular core module which is good for basic scenarios
• Non official router
• Created by the community
• Used by 99.9% of devs
• More popular than ngRoute
• Mainly used in Nested/Complex views
ANGULARJS
UI-ROUTER
EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js
UI Route over ng-Route
EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js
AngularJS Routers
UI-Route over NgRoute
UI-Router allows for nested
views and multiple views
UI-Router allows for you to have
strong-type linking between states
based on state names
You can easily pass information
between states
Change the url in one place will update
every link to that state when you build
your links with ui-sref
States allow you to map and access
different information about different
states
Concept of the decorator in UI-Router,
allows your routes to be dynamically
created based on the URL
EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js
UI-Router vs NgRoute
Parameters UI-Router NgRoute
Module name (dependent module) ui.router
angular.module('app', ['ui.router']);
ngRoute
angular.module('app', ['ngRoute']);
Router provider $stateProvider
$urlRouterProvider
$routeProvider
Simple Syntax $stateProvider.state('customersState', {
url: '/customers', template: 'My
Customers' })
$routeProvider.when('/customers', {
template: 'My Customers' });
Template view directive ui-view ng-view
Template named view directive ui-view="customers" ---
Link directive ui-sref=""
a ui-sref="customersState"> Customers
</a>
href=""
<a href="#/customers"> Customers
</a>
EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js
UI-Router vs NgRoute
Parameters UI-Router NgRoute
Getting Params (as a service) $state
(eg) $state.params.id
$stateParams
(eg) $stateParams.id
$route
(eg) $route.current.params.id
$routeParams
(eg) $routeParams.id
Router start event $stateChangeStart $routeChangeStart
Router success event $stateChangeSuccess $routeChangeSuccess
Router error event $stateChangeError $routeChangeError
Router update event --- $routeUpdate
Router not found event $stateNotFound ---
EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js
UI-Router vs NgRoute
Parameters UI-Router NgRoute
Default View $urlRouterProvider.otherwise('/custom
ers');
$routeProvider.otherwise({redirectTo:
'/customers'});
One view to another view $state.go('customersState'); $location.path( "/customers" );
One view to another view with params $state.go('customersState', {id:'123'}); $location.path( "/customer/123" );
EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js
Angular Router
EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js
Angular Router
• Official Angular Router
• Inspired by the UI-Router
• Complete rewrite as compared to ng-
Route
• Introduction of Route in place of State
ANGULAR
ROUTER
Component
1
Component
3
Component
6
Component
4
Component
5
Component
2
EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js
Router
A router allows us to navigate across components in a Web App
Navbar Component
About Component
Movies Component
Home Component
Home Page View of
the App
It contains the About
section
It shows the list of top 250
movies
Responsible for
navigation among
components
EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js
A Closer Look at Router
EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js
Router
Path Declaration for different
components
Passing Declared Paths Array to
RouterModule
EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js
routerLink
Navigation from Movies List Component to Move
Details Component
MoviesComponent MoviesDetailsComponent
[ routerLink ] = “ [ ‘ < path >’ ] ”
EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js
<router-outlet>
Allows to navigate to a Component
by pasting its path in Browser Address Bar
EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js
<router-outlet>
Home Page Movies List
Add ‘/movies’ to Browser Address Bar
EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js
Angular Router vs UI-Router
EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js
UI-Router vs Angular Router
UI ROUTER ANGULAR ROUTER
• A Route in Angular Router
• A Route is the association of a name, a path and
a component
• A State in UI Router
• A State is the association of a name, a url, a
template and a controller
AngularJS Angular
EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js
UI-Router vs Angular Router
• A Route in Angular Router
• A Route is the association of a name, a path and
a component
• A State in UI Router
• A State is the association of a name, a url, a
template and a controller
UI ROUTER ANGULAR ROUTER
AngularJS Angular
EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js
Nested Views
Navigation Bar
Side Bar
Course1
Course3
Course4
Course2
View inside a view  Course List inside Root Component
EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js
Nested Views
UI ROUTER ANGULAR ROUTER
AngularJS Angular
EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js
Built-in Router Directives
routerLink directive for Angular routerui-sref directive for UI router
UI ROUTER ANGULAR ROUTER
AngularJS Angular
EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js
Built-in Router Directives
routerLink directive for Angular routerui-sref directive for UI router
UI ROUTER ANGULAR ROUTER
AngularJS Angular
EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js
URL Data
Get the id from /course-details/:id
id of every course
EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js
URL Data
Get the id from /course-details/:id
RouteParams service for Angular2 Router$stateParams service for UI-Router
id of every course
UI ROUTER ANGULAR ROUTER
AngularJS Angular
EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js
Angular Router Demo
EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js
Demo
Navbar Component
About Component
Course Component
Home Component
Home Page View of
the App
It contains the About
section
It shows the list Edureka
courses
Responsible for navigation
among components
EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js
Demo
Add ‘/course’ to Browser Address Bar
Navigating to Course Detail Component
EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js
Demo
Course Component
(Displays the list of courses)
Navbar Component
Course
Component
About
Component
Course Component
Navbar Component
Course
Component
About
Component
Firebase
Service
Course Details Component
(Displays the details of course selected)
EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js
Thank You …
Questions/Queries/Feedback

More Related Content

What's hot (20)

ODP
Angular 6 - The Complete Guide
Sam Dias
 
PPSX
Angular 4 fronts
badal dubla
 
PDF
Developing a Demo Application with Angular 4 - J2I
Nader Debbabi
 
PDF
Meetup SkillValue - Angular 6 : Bien démarrer son application
Thibault Even
 
PPTX
An Overview of Angular 4
Cynoteck Technology Solutions Private Limited
 
PDF
What angular 13 will bring to the table
Moon Technolabs Pvt. Ltd.
 
PDF
Mastering angular - Dot Net Tricks
Gaurav Singh
 
PPTX
Meetup angular http client
Gaurav Madaan
 
PPTX
Angular 9 New features
Ahmed Bouchefra
 
ODP
A Glimpse on Angular 4
Sam Dias
 
PPTX
Angular
Mouad EL Fakir
 
PDF
Angular routing
Sultan Ahmed
 
PPTX
OCTO BOF - How to build Netvibes with AngularJS
Jonathan Meiss
 
PPTX
Angular vs. AngularJS: A Complete Comparison Guide
Cloud Analogy
 
PDF
Angularjs tutorial
HarikaReddy115
 
PDF
Introduction to angular 4
Marwane El Azami
 
PPTX
Angular 2 - Better or worse
Vladimir Georgiev
 
PPTX
Angular 2
Nigam Goyal
 
PDF
AngularJS
Hiten Pratap Singh
 
DOCX
Angular js training in noida
nihalsingh113
 
Angular 6 - The Complete Guide
Sam Dias
 
Angular 4 fronts
badal dubla
 
Developing a Demo Application with Angular 4 - J2I
Nader Debbabi
 
Meetup SkillValue - Angular 6 : Bien démarrer son application
Thibault Even
 
What angular 13 will bring to the table
Moon Technolabs Pvt. Ltd.
 
Mastering angular - Dot Net Tricks
Gaurav Singh
 
Meetup angular http client
Gaurav Madaan
 
Angular 9 New features
Ahmed Bouchefra
 
A Glimpse on Angular 4
Sam Dias
 
Angular routing
Sultan Ahmed
 
OCTO BOF - How to build Netvibes with AngularJS
Jonathan Meiss
 
Angular vs. AngularJS: A Complete Comparison Guide
Cloud Analogy
 
Angularjs tutorial
HarikaReddy115
 
Introduction to angular 4
Marwane El Azami
 
Angular 2 - Better or worse
Vladimir Georgiev
 
Angular 2
Nigam Goyal
 
Angular js training in noida
nihalsingh113
 

Similar to Angular Routing Tutorial | AngularJS vs Angular Router | Angular Training | Edureka (20)

PDF
Angular js routing options
Nir Kaufman
 
PDF
Intro to UI-Router/TypeScript
Jamal Sinclair O'Garro
 
PDF
Deep Dive into AngularJS Javascript Framework
Edureka!
 
PDF
Beyond AngularJS: Best practices and more
Ari Lerner
 
PPTX
ngNewRouter
phidong
 
PPTX
UQ21CA642BA1-Unit-3-WAF-Class18-Introduction to Angular Routing.pptx
TamalDey28
 
ODP
Routing & Navigating Pages in Angular 2
Knoldus Inc.
 
PPTX
Angular2 routing
TejinderMakkar
 
PDF
Building Better Web Apps with Angular.js (SXSW 2014)
kbekessy
 
DOCX
How routing works in angular js
codeandyou forums
 
PPTX
UI-Router
Loc Nguyen
 
DOCX
Understand routing in angular 2
codeandyou forums
 
PDF
Angularjs
Ynon Perek
 
PDF
Angular 4 Tutorial For Beginners | Angular 4 Introduction | Angular 4 Trainin...
Edureka!
 
PDF
How to Implement Basic Angular Routing and Nested Routing With Params in Angu...
Katy Slemon
 
PDF
AngularJS for Beginners
Edureka!
 
PDF
ngconf2015
Anne Cypcar
 
PDF
Angular JS Routing
kennystoltz
 
PPTX
AngularJS Introduction (Talk given on Aug 5 2013)
Abhishek Anand
 
PDF
Getting Started with AngularJS
Edureka!
 
Angular js routing options
Nir Kaufman
 
Intro to UI-Router/TypeScript
Jamal Sinclair O'Garro
 
Deep Dive into AngularJS Javascript Framework
Edureka!
 
Beyond AngularJS: Best practices and more
Ari Lerner
 
ngNewRouter
phidong
 
UQ21CA642BA1-Unit-3-WAF-Class18-Introduction to Angular Routing.pptx
TamalDey28
 
Routing & Navigating Pages in Angular 2
Knoldus Inc.
 
Angular2 routing
TejinderMakkar
 
Building Better Web Apps with Angular.js (SXSW 2014)
kbekessy
 
How routing works in angular js
codeandyou forums
 
UI-Router
Loc Nguyen
 
Understand routing in angular 2
codeandyou forums
 
Angularjs
Ynon Perek
 
Angular 4 Tutorial For Beginners | Angular 4 Introduction | Angular 4 Trainin...
Edureka!
 
How to Implement Basic Angular Routing and Nested Routing With Params in Angu...
Katy Slemon
 
AngularJS for Beginners
Edureka!
 
ngconf2015
Anne Cypcar
 
Angular JS Routing
kennystoltz
 
AngularJS Introduction (Talk given on Aug 5 2013)
Abhishek Anand
 
Getting Started with AngularJS
Edureka!
 
Ad

More from Edureka! (20)

PDF
What to learn during the 21 days Lockdown | Edureka
Edureka!
 
PDF
Top 10 Dying Programming Languages in 2020 | Edureka
Edureka!
 
PDF
Top 5 Trending Business Intelligence Tools | Edureka
Edureka!
 
PDF
Tableau Tutorial for Data Science | Edureka
Edureka!
 
PDF
Python Programming Tutorial | Edureka
Edureka!
 
PDF
Top 5 PMP Certifications | Edureka
Edureka!
 
PDF
Top Maven Interview Questions in 2020 | Edureka
Edureka!
 
PDF
Linux Mint Tutorial | Edureka
Edureka!
 
PDF
How to Deploy Java Web App in AWS| Edureka
Edureka!
 
PDF
Importance of Digital Marketing | Edureka
Edureka!
 
PDF
RPA in 2020 | Edureka
Edureka!
 
PDF
Email Notifications in Jenkins | Edureka
Edureka!
 
PDF
EA Algorithm in Machine Learning | Edureka
Edureka!
 
PDF
Cognitive AI Tutorial | Edureka
Edureka!
 
PDF
AWS Cloud Practitioner Tutorial | Edureka
Edureka!
 
PDF
Blue Prism Top Interview Questions | Edureka
Edureka!
 
PDF
Big Data on AWS Tutorial | Edureka
Edureka!
 
PDF
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
Edureka!
 
PDF
Kubernetes Installation on Ubuntu | Edureka
Edureka!
 
PDF
Introduction to DevOps | Edureka
Edureka!
 
What to learn during the 21 days Lockdown | Edureka
Edureka!
 
Top 10 Dying Programming Languages in 2020 | Edureka
Edureka!
 
Top 5 Trending Business Intelligence Tools | Edureka
Edureka!
 
Tableau Tutorial for Data Science | Edureka
Edureka!
 
Python Programming Tutorial | Edureka
Edureka!
 
Top 5 PMP Certifications | Edureka
Edureka!
 
Top Maven Interview Questions in 2020 | Edureka
Edureka!
 
Linux Mint Tutorial | Edureka
Edureka!
 
How to Deploy Java Web App in AWS| Edureka
Edureka!
 
Importance of Digital Marketing | Edureka
Edureka!
 
RPA in 2020 | Edureka
Edureka!
 
Email Notifications in Jenkins | Edureka
Edureka!
 
EA Algorithm in Machine Learning | Edureka
Edureka!
 
Cognitive AI Tutorial | Edureka
Edureka!
 
AWS Cloud Practitioner Tutorial | Edureka
Edureka!
 
Blue Prism Top Interview Questions | Edureka
Edureka!
 
Big Data on AWS Tutorial | Edureka
Edureka!
 
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
Edureka!
 
Kubernetes Installation on Ubuntu | Edureka
Edureka!
 
Introduction to DevOps | Edureka
Edureka!
 
Ad

Recently uploaded (20)

PDF
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
PPTX
Top iOS App Development Company in the USA for Innovative Apps
SynapseIndia
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PPT
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PPTX
MSP360 Backup Scheduling and Retention Best Practices.pptx
MSP360
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PDF
Python basic programing language for automation
DanialHabibi2
 
PDF
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
Top iOS App Development Company in the USA for Innovative Apps
SynapseIndia
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
MSP360 Backup Scheduling and Retention Best Practices.pptx
MSP360
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
Python basic programing language for automation
DanialHabibi2
 
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 

Angular Routing Tutorial | AngularJS vs Angular Router | Angular Training | Edureka

  • 2. EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js Agenda Why Routers? 1 What is Routers? 2 AngularJS Routers 3 Angular Router 4 Demo 6 Diff b/w AngularJS and Angular Routers 5
  • 3. EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js Why we need Routers?
  • 4. EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js Why we need Routers? Navigation Bar Side Bar Course List While navigating through a Single Page Application… Navbar Component Side Bar Component Course List Component
  • 5. EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js Why we need Routers? Navigation Bar Side Bar Course1 Course3 Course4 Course2 If you reload a part (Course List), it only renders that component without fetching the whole page (i.e. Navigation Bar & Side Bar) from server
  • 6. EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js Why we need Routers? Navigation Bar Side Bar Course 2 Description: … … … … … … Similarly, if you select a course, it only renders Course Description instead of reloading the whole page
  • 7. EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js For a real-time example
  • 8. EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js Why we need Routers? In Gmail inbox while clicking on a mail…
  • 9. EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js Why we need Routers? It only reloads the concerned section, without interfering the rest of the part …
  • 10. EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js Without reloading the whole page we can navigate between components Thanks to Routers!!!
  • 11. EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js What is Router?
  • 12. EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js What is Router? Routing is used for navigating among different components in your SPA (Single Page Application) Component 1 Component 3 Component 6 Component 4 Component 5 Component 2
  • 13. EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js AngularJS Routers
  • 14. EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js AngularJS Routers NgRoute UI-Router UI-Router is a contributed module which is overcome the problems of ngRoute. Mainly Nested/Complex views. ngRoute is a angular core module which is good for basic scenarios • Non official router • Created by the community • Used by 99.9% of devs • More popular than ngRoute • Mainly used in Nested/Complex views ANGULARJS UI-ROUTER
  • 15. EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js UI Route over ng-Route
  • 16. EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js AngularJS Routers UI-Route over NgRoute UI-Router allows for nested views and multiple views UI-Router allows for you to have strong-type linking between states based on state names You can easily pass information between states Change the url in one place will update every link to that state when you build your links with ui-sref States allow you to map and access different information about different states Concept of the decorator in UI-Router, allows your routes to be dynamically created based on the URL
  • 17. EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js UI-Router vs NgRoute Parameters UI-Router NgRoute Module name (dependent module) ui.router angular.module('app', ['ui.router']); ngRoute angular.module('app', ['ngRoute']); Router provider $stateProvider $urlRouterProvider $routeProvider Simple Syntax $stateProvider.state('customersState', { url: '/customers', template: 'My Customers' }) $routeProvider.when('/customers', { template: 'My Customers' }); Template view directive ui-view ng-view Template named view directive ui-view="customers" --- Link directive ui-sref="" a ui-sref="customersState"> Customers </a> href="" <a href="#/customers"> Customers </a>
  • 18. EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js UI-Router vs NgRoute Parameters UI-Router NgRoute Getting Params (as a service) $state (eg) $state.params.id $stateParams (eg) $stateParams.id $route (eg) $route.current.params.id $routeParams (eg) $routeParams.id Router start event $stateChangeStart $routeChangeStart Router success event $stateChangeSuccess $routeChangeSuccess Router error event $stateChangeError $routeChangeError Router update event --- $routeUpdate Router not found event $stateNotFound ---
  • 19. EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js UI-Router vs NgRoute Parameters UI-Router NgRoute Default View $urlRouterProvider.otherwise('/custom ers'); $routeProvider.otherwise({redirectTo: '/customers'}); One view to another view $state.go('customersState'); $location.path( "/customers" ); One view to another view with params $state.go('customersState', {id:'123'}); $location.path( "/customer/123" );
  • 20. EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js Angular Router
  • 21. EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js Angular Router • Official Angular Router • Inspired by the UI-Router • Complete rewrite as compared to ng- Route • Introduction of Route in place of State ANGULAR ROUTER Component 1 Component 3 Component 6 Component 4 Component 5 Component 2
  • 22. EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js Router A router allows us to navigate across components in a Web App Navbar Component About Component Movies Component Home Component Home Page View of the App It contains the About section It shows the list of top 250 movies Responsible for navigation among components
  • 23. EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js A Closer Look at Router
  • 24. EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js Router Path Declaration for different components Passing Declared Paths Array to RouterModule
  • 25. EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js routerLink Navigation from Movies List Component to Move Details Component MoviesComponent MoviesDetailsComponent [ routerLink ] = “ [ ‘ < path >’ ] ”
  • 26. EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js <router-outlet> Allows to navigate to a Component by pasting its path in Browser Address Bar
  • 27. EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js <router-outlet> Home Page Movies List Add ‘/movies’ to Browser Address Bar
  • 28. EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js Angular Router vs UI-Router
  • 29. EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js UI-Router vs Angular Router UI ROUTER ANGULAR ROUTER • A Route in Angular Router • A Route is the association of a name, a path and a component • A State in UI Router • A State is the association of a name, a url, a template and a controller AngularJS Angular
  • 30. EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js UI-Router vs Angular Router • A Route in Angular Router • A Route is the association of a name, a path and a component • A State in UI Router • A State is the association of a name, a url, a template and a controller UI ROUTER ANGULAR ROUTER AngularJS Angular
  • 31. EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js Nested Views Navigation Bar Side Bar Course1 Course3 Course4 Course2 View inside a view  Course List inside Root Component
  • 32. EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js Nested Views UI ROUTER ANGULAR ROUTER AngularJS Angular
  • 33. EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js Built-in Router Directives routerLink directive for Angular routerui-sref directive for UI router UI ROUTER ANGULAR ROUTER AngularJS Angular
  • 34. EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js Built-in Router Directives routerLink directive for Angular routerui-sref directive for UI router UI ROUTER ANGULAR ROUTER AngularJS Angular
  • 35. EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js URL Data Get the id from /course-details/:id id of every course
  • 36. EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js URL Data Get the id from /course-details/:id RouteParams service for Angular2 Router$stateParams service for UI-Router id of every course UI ROUTER ANGULAR ROUTER AngularJS Angular
  • 37. EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js Angular Router Demo
  • 38. EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js Demo Navbar Component About Component Course Component Home Component Home Page View of the App It contains the About section It shows the list Edureka courses Responsible for navigation among components
  • 39. EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js Demo Add ‘/course’ to Browser Address Bar Navigating to Course Detail Component
  • 40. EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js Demo Course Component (Displays the list of courses) Navbar Component Course Component About Component Course Component Navbar Component Course Component About Component Firebase Service Course Details Component (Displays the details of course selected)
  • 41. EDUREKA ANGULARJS CERTIFICATION TRAINING www.edureka.co/angular-js Thank You … Questions/Queries/Feedback