artch/angular-route-segment

routeSegmentChange issue

Opened this issue · 1 comments

Hi All,

is there any way to prevent the location changing?

$rootScope.$on("routeSegmentChange", function (index, segment) {
    if (!isUserAllowed(segment, _authentication.role)) {
        // cancel the segment changing
    }
});

Thank you in advance!

dviz commented

no native support. But you can modify lib source by adding cancel property:

                                 $rootScope.$broadcast('routeSegmentChange', {
                                     index: index,
                                     segment: $routeSegment.chain[index] || null,
                                     cancel : false
                                 });

and :

                        if (args.index == viewSegmentIndex && currentSegment != args.segment && !args.cancel)
                            update(args.segment);

And in app do like:
app.run(['$rootScope', function ($rootScope) {
$rootScope.$on("routeSegmentChange", function (index, args) {
args.cancel = true;
});
}]);