This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
event.preventDefault() does not work in $routeChangeStart after $route.reload() #9824
Closed
Description
Angular version 1.3.0
Failing code
$rootScope.$on('$routeChangeStart', function(event, curr, prev) {
if (...condition1...) {
event.preventDefault();
// do something to get condition1 == false
$route.reload();
}
if (...condition2...) {
event.preventDefault(); // <-- this is not preventing
// do something to get condition2 == false
$route.reload();
}
});
Issue in source
reload: function() {
forceReload = true;
$rootScope.$evalAsync(function() {
// Don't support cancellation of a reload for now...
prepareRoute(); // <-- param is empty
commitRoute();
});
},
...
function prepareRoute($locationEvent) {
var lastRoute = $route.current;
preparedRoute = parseRoute();
preparedRouteIsUpdateOnly = preparedRoute && lastRoute && preparedRoute.$$route === lastRoute.$$route
&& angular.equals(preparedRoute.pathParams, lastRoute.pathParams)
&& !preparedRoute.reloadOnSearch && !forceReload;
if (!preparedRouteIsUpdateOnly && (lastRoute || preparedRoute)) {
if ($rootScope.$broadcast('$routeChangeStart', preparedRoute, lastRoute).defaultPrevented) {
if ($locationEvent) { <-- is undefined
$locationEvent.preventDefault();
}
}
}
}