Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Update route.js #5855

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/ngRoute/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,25 @@ function $RouteProvider(){
* instance of the Controller.
*/

/**
* @ngdoc event
* @name ngRoute.$route#beforeRouteChange
* @eventOf ngRoute.$route
* @eventType broadcast on root scope
* @description
* Broadcasted at the same time as locationChangeStart,
* passes through the event so the locationChange can be cancelled.
* Passes two other objects that represent the Routes of the current location
* and the one of the possible next.
*
* `$beforeRouteChange` is fired.
*
* @param {Object} angularEvent Synthetic event object.
* @param {Route} currentRoute current route information.
* @param {Route} nextRoute route information of the future route.
* @param {Object} angularEvent Synthetic event object of locationChangeStart.
*/

var forceReload = false,
$route = {
routes: routes,
Expand All @@ -444,6 +463,13 @@ function $RouteProvider(){
};

$rootScope.$on('$locationChangeSuccess', updateRoute);

$rootScope.$on("$locationChangeStart", function (event, next, current) {
var nextRoute = parseRoute(),
lastRoute = $route.current;

$rootScope.$broadcast('$beforeRouteChange', lastRoute, nextRoute, event);
});

return $route;

Expand Down