I have been searching everywhere for a solution to this issue. My goal is to be able to access the routing parameters collection and prevent the route from loading if a certain parameter is missing. I have tried using preventDefault in $routeChangeStart, but it did not work for me. It seems to only work in $locationChangeStart, which unfortunately does not provide access to the routing parameters collection.
Is there a way to determine if a specific routing parameter is missing and cancel the route accordingly?
$rootScope.$on('$locationChangeStart', function (event, next, current) {
// Handle case when no route parameters are present
});
$rootScope.$on('$routeChangeStart', function (event, next) {
if (!($.isNumeric(next.params.siteId) && +next.params.siteId)) {
event.preventDefault(); // This method didn't work for me
$location.url('home');
}
});
I have come across some solutions mentioned in other posts, but they all seem tailored to ngRoute specifically. However, I am using angular routing segment instead.