var app = angular.module('plunker', ['ui.router'])
.config(appConfig)
.controller('MainCtrl', MainCtrl);
appConfig.$inject = ['$stateProvider', '$urlRouterProvider']
function appConfig($stateProvider, $urlRouterProvider) {
$stateProvider.state({
name: 'hello',
url: '/hello',
template: '<h3>HOME! Inspect the console</h3>'
})
.state({
name: 'about',
url: '/about',
template: '<h3>ABOUT! Inspect the console</h3>'
})
.state({
name: 'about.blah',
url: '',
template: '<h3>ABOUT! Inspect the console</h3>'
});
$urlRouterProvider.otherwise('/hello');
}
MainCtrl.$inject = ['$transitions'];
function MainCtrl($transitions) {
$transitions.onExit({}, function(transition) {
console.log('state change exit');
console.log(transition.to());
console.log(transition.from());
});
}
<!DOCTYPE html>
<html ng-app="plunker">
<head>
<meta charset="utf-8" />
<title>AngularJS UI Router State changes transitions (0.4.2/1.0.0)</title>
<link rel="stylesheet" href="style.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.4/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/1.0.3/angular-ui-router.js"></script>
<script src="app.js"></script>
</head>
<body ng-controller="MainCtrl">
<a ui-sref="hello" ui-sref-active="active">Hello</a>
<a ui-sref="about.blah" ui-sref-active="active">About</a>
<ui-view></ui-view>
</body>
</html>
/* Put your css in here */
.active {
color: red;
font-weight: bold;
}