Add angular-route to angular project on ubuntu 16

install angular route

npm install angular-route --save

add angular route to module dependencies in app.js

var myApp = angular.module('myApp', ['ngRoute']);

include angular-route.js into index.html

<script src="node_modules/angular-route/angular-route.js"></script>

configure routing in app.js

//Routing
myApp.config(function($routeProvider, $locationProvider) {
$locationProvider.hashPrefix('');

$routeProvider.when('/first', {
templateUrl: 'first.html',
controller: 'FirstController'
})
.when('/second', {
templateUrl: 'second.html',
controller: 'SecondController'
}).otherwise({
redirectTo: '/first'
});
});


myApp.controller('FirstController', ['$scope', function($scope) {
 $scope.greeting = 'First!';
}]);
myApp.controller('SecondController', ['$scope', function($scope) {
 $scope.greeting = 'Second!';
}]);

create first.html and second.html files into your project and add same content

 <h1>{{greeting}}</h1>

add ng-view directive into your index.html

 <div ng-view></div>

Now you can access your two views calling
http://example.com/first
http://example.com/second

Certainly you’d like to add some navigation into your index.html too

 <a class="nav-link" href="#first">First</a>
 <a class="nav-link" href="#second">Second</a>