Angular routeProvider set of declared parameters?

Is it possible to allow only certain options in routeProvider with angularjs?

For example, if I have:

$routeProvider.when('/:action/view/', {

Can I authorize (“basketball”, “baseball”), as an action for this, so that it is set as a match?

+4
source share
2 answers

you can use the redirectTo attribute of your route to redirect users in case of an invalid route call:

$routeProvider.when('/:action/view/',{
    redirectTo: function(routeParams, locationPath, locationSearch){
        var allowed = ['baseball','basketball'];        //allowed action param

        if(allowed.indexOf(routeParams.action) != -1){  //route is allowed don't redirect
            return null;
        }
        else{                                           //route is denied redirect to home
            return '/home';
        }
    }
}
0
source

, $routeChangeStart, , "next" "current" route, , . , $location.path, .

0

All Articles