Angular $ routeProvider以不同方式处理不同的URL

时间:2015-07-30 21:35:19

标签: javascript angularjs

在角度方面,是否有一种加载不同视图的方法&控制器当路由基本相同时,但路由中的实际字符串是不同的?

就路由而言,如果已经使用了顶级路由参数,是否可以加载不同的View&控制器基于不同的路由参数?

以下是我的尝试:

app.config(['$routeProvider',
  function($routeProvider) {
    $routeProvider
      .when("/", {
        templateUrl: "app/components/0_home/homeView.html",
        controller: "HomeController"
      }) // Home
      .when("/about", {
        templateUrl: "app/components/1_about/aboutView.html",
        controller: "AboutController"
      }) // About
      /*(...Bunch of other .whens)*/

    //Project
    .when("/project/:projectId", {
        templateUrl: "app/components_project/0_home/homeView.html",
        controller: "ProjectHomeController"
      })
      .when("/project/:projectId/HOME", {
        templateUrl: "app/components_project/0_home/homeView.html",
        controller: "ProjectHomeController"
      })
      .when("/project/:projectId/FLOORPLAN", {
        templateUrl: "app/components_project/1_floorplans/floorplanView.html",
        controller: "FloorplanController"
      }) // Floorplan
    .when("/404", {
        templateUrl: "app/components/404.html"
      }) // else 404
      .otherwise({
        redirectTo: '/404'
      });
  }
]);

我想加载

  

应用程序/ components_project / 0_home / homeView.html

当routeProvider是

  

/项目/:专案编号/ HOME

并加载

  

应用程序/ components_project / 1_floorplans / floorplanView.html

当routeProvider是

  

/项目/:专案编号/楼层平面图

或者有没有更好的方法来处理这种情况?

0 个答案:

没有答案