在$ routeProvider中组合.when()方法

时间:2015-05-18 20:01:19

标签: javascript angularjs route-provider

在我的代码中,路径“/”和“/ A”需要相同的模板和控制器。是否可以为单个.when()方法包含多个路由?如果是这样,这些路线如何组合?

$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: '/' 
    });

2 个答案:

答案 0 :(得分:3)

如何重定向 when("/A", { redirectTo: '/' } ). 请求?

<?php
   $commande ="java -jar file.jar";
   $commande2 ="load file;;";

   //$fichier  ="file.jar";
   exec("$commande");
   exec("$commande2");
?>

答案 1 :(得分:1)

您可以考虑参数化路线吗?如果A不是静态的,那就是要走的路。你会有这样的事情:

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