var app = angular.module('plunker', ['ngRoute']);
app.config(function($routeProvider) {
$routeProvider
.when('/', {
controller: 'homeController',
template: '<h2>Home</h2>'
})
.when('/about', {
controller: 'aboutController',
template: '<h2>About</h2>'
})
.otherwise({
controller: '404Controller',
templateUrl: '404.html'
});
});
app.controller('appController', function($scope, $location) {
$scope.isActive = function(path) {
return $location.path() === path;
};
});
app.controller('homeController', function($scope) {});
app.controller('aboutController', function($scope) {});
app.controller('404Controller', function($scope, $location) {
$scope.path = $location.path();
$scope.back = function() {
history.back();
};
});
<!DOCTYPE html>
<html ng-app="plunker">
<head>
<meta charset="utf-8" />
<title>AngularJS Plunker</title>
<link data-require="bootstrap-css@*" data-semver="3.2.0" rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" />
<script>
document.write('<base href="' + document.location + '" />');
</script>
<link rel="stylesheet" href="style.css" />
<script data-require="angular.js@1.2.x" src="https://code.angularjs.org/1.2.20/angular.js" data-semver="1.2.20"></script>
<script data-require="angular-route@*" data-semver="1.2.17" src="http://code.angularjs.org/1.2.17/angular-route.js"></script>
<script src="app.js"></script>
</head>
<body ng-controller="appController">
<div class="container">
<ul class="nav nav-pills">
<li ng-class="{active: isActive('/')}"><a href="#">Home</a></li>
<li ng-class="{active: isActive('/about')}"><a href="#/about">About</a></li>
<li ng-class="{active: isActive('/badlink')}"><a href="#/badlink" class="text-danger">Bad link</a></li>
</ul>
<div ng-view=""></div>
</div>
</body>
</html>
/* Put your css in here */
.container {
padding-top: 20px;
}
<h2>404 Not Found</h2>
<p>Oops! Path <code>{{path}}</code> is not found.</p>
<p>You can go <a href="" ng-click="back()">back</a> or <a href="#">home</a> instead.</p>