【问题标题】:Routing in AngularAngular中的路由
【发布时间】:2016-11-24 18:47:42
【问题描述】:

如何以只能获取 template.html 而不能获取 template1.html 的方式组织以下代码?

App.config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) {
  $locationProvider.html5Mode({
    enabled: true,
    requireBase: false
  });
  $routeProvider
    .when('/', {
      templateUrl: "template/home.html",
      controller: "homeCtrl"
    })
    .when('/artist', {
      templateUrl: "template/artist.html",
      controller: "artistCtrl"
    })
    .when('/:collectionId', {
      templateUrl: "template/template.html",
      controller: "templateCtrl"
    })
    .when('/:trackId', {
      templateUrl: "template/template1.html",
      controller: "templateCtrl"
    })
    .otherwise({
      redirectTo: "/"
    });
}]);

感谢您的帮助!

【问题讨论】:

  • 你的问题不清楚
  • 使用'/collection/:id''/track/:id' 作为路由。

标签: javascript html angularjs templates


【解决方案1】:

您应该重命名您的路线。

.when('/collection:id', {
    templateUrl: 'your/template.html',
    controller: 'yourController'
  });
})

【讨论】:

    猜你喜欢
    • 2018-12-20
    • 1970-01-01
    • 2018-04-09
    • 2016-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-07
    相关资源
    最近更新 更多