Search code examples
javascriptangularjsroute-provider

Combining .when() method in $routeProvider


In my code, the paths, "/" and "/A" call for the same template and controller. Is it possible to include multiple routes for the a single .when() method? If so, how can these routes be combined?

$routeProvider.
    when("/", {
        templateUrl: "templates/A.html",
        controller: "AController"
    }).   
    when("/B", {
        templateUrl: "templates/B.html",
        controller: "BController"
    }).   
    when("/A", {
        templateUrl: "templates/A.html",
        controller: "AController",          
    }).
    otherwise({ 
        redirectTo: '/' 
    });

Solution

  • How about redirecting the /A request?

        when("/A", { redirectTo: '/' } ).