Curriculum
Course: AngularJS
Login

Curriculum

AngularJS

AngularJS Tutorial

0/65
Text lesson

AngularJS Routing

The ngRoute module enables your application to function as a Single Page Application.

What is Routing in AngularJS?

To navigate between different pages in your application while maintaining the behavior of a Single Page Application (SPA) without full page reloads, you can use the ngRoute module. It enables routing to different views without refreshing the entire application.

Example:

Access “red.htm,” “green.htm,” and “blue.htm.”

<body ng-app=”myApp”>

<p><a href=”#/!”>Main</a></p>

<a href=”#!red”>Red</a>
<a href=”#!green”>Green</a>
<a href=”#!blue”>Blue</a>

<div ng-view></div>

<script>
var app = angular.module(“myApp”, [“ngRoute”]);
app.config(function($routeProvider) {
  $routeProvider
  .when(“/”, {
    templateUrl : “main.htm”
  })
  .when(“/red”, {
    templateUrl : “red.htm”
  })
  .when(“/green”, {
    templateUrl : “green.htm”
  })
  .when(“/blue”, {
    templateUrl : “blue.htm”
  });
});
</script>
</body>