How to detect a route change in AngularJS ? Last Updated : 06 Sep, 2022 Summarize Comments Improve Suggest changes Share Like Article Like Report In this article, we will see how to detect a route change in AngularJS. In order to detect route change at any moment in AngularJS, this can be achieved by using the $on() method. The $on() method is an event handler, the event which will handle $routeChangeSuccess which gets triggered when route/view change is done. Syntax: $rootScope.$on('$routeChangeSuccess', function () { Content... });Approach: Here, we are displaying "route changed" in the console window whenever there is any route change. Inside the $on() method, we console route changed. Hence, In this way whenever route change occurs, it triggers $routeChangeSuccess handled by $on() event handler, and then "route changed" is displayed in the console window. Example: This example describes the process to detect a route change in AngularJS. HTML <!DOCTYPE html> <html> <head> <title>Angular JS Route Change</title> <script src= "https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"> </script> <script src= "https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular-route.min.js"> </script> </head> <body style="text-align:center;"> <h1 style="color:green;"> GeeksforGeeks </h1> <h3>Detecting the route change in AngularJS </h3> <div> <p> <a href="#viewLink1">Link 1</a> </p> <p> <a href="#viewLink2">Link 2</a> </p> <div ng-app="mainApp" ng-controller="GFGController"> <div ng-view></div> </div> </div> <script> var mainApp = angular.module("mainApp", ['ngRoute']); mainApp.config(['$routeProvider', function($routeProvider) { $routeProvider.when('/viewLink1', { template: "<p> This is Link 1 </p>" }).when('/viewLink2', { template: "<p> This is Link 2 </p>" }).otherwise({ redirectTo: '/viewLink1' }); }]); mainApp.controller('GFGController', function($scope, $location, $rootScope) { $rootScope.$on('$routeChangeSuccess', function() { console.log("route changed"); }); }); </script> </body> </html> Output: As we change the link, the $routeChangeSuccess event gets triggered, and thus displays route changes in the console window. Comment More infoAdvertise with us Next Article How to detect a route change in AngularJS ? P pratyushranjan14 Follow Improve Article Tags : Web Technologies AngularJS AngularJS-Questions Similar Reads How to determine active route in AngularJS ? In this article, we will see how to determine the active route in AngularJS, along with understanding the basic implementation through the example. Approach: To determine which is the active route at any moment in AngularJS this can be achieved by using $on() & $location.path() method. An event 2 min read How to detect when an @Input() value changes in Angular? @Input() is basically a decorator to bind a property as an input. It is used to pass data i.e property binding from one component to other or we can say, from parent to child component. It is bound with the DOM element. When the DOM element value is changed, Angular automatically updates this proper 3 min read How do you configure routes in Angular? In Angular, configuring routes is an important part of building single-page applications (SPAs) and managing navigation between different components. By defining routes, we can map URLs to specific components, enabling users to access different views within our application. This enhances user experi 5 min read How to Get All Route Params/Data in Angular? In Angular, managing route parameters and extracting data from routes is important for creating dynamic and responsive web applications. Route parameters allow you to pass information in URLs, and accessing this data enables your application to make decisions and render content dynamically. This art 4 min read How to execute a routing in the AngularJS framework ? In this article, we will learn about how we can perform routing in AngularJS, along with understanding its implementation through the code example. Â Routing in AngularJS helps to develop Single Page Applications, which is a web app that loads only a single page, and the part of the page instead of t 6 min read Like