我有以下问题:
我的angularJS应用程序有以下路由器:
var app = angular.module('imagesApp', ['ngRoute']);
app.config(function($routeProvider, $locationProvider) {
$locationProvider.html5Mode(true);
$routeProvider
.when('/', {
templateUrl : 'albums.html',
controller : 'imagesCtrl'
})
.when('/:genre', {
templateUrl : 'albums.html',
controller : 'genreCtrl'
})
.when('/album/:id', {
templateUrl : 'product.html',
controller : 'itemCtrl'
});
});
app.controller('imagesCtrl', function($scope, $http) {
$http.get("http://localhost/api/index.php/album")
.then(function (response) {
$scope.images = response.data.msg.albums;
});
});
app.controller('genreCtrl', function($scope, $http, $routeParams) {
$http.get("http://localhost/api/index.php/"+$routeParams.genre)
.then(function (response) {
$scope.images = response.data.msg.albums;
});
});
app.controller('itemCtrl', function($scope, $http, $routeParams) {
$http.get("http://localhost/api/index.php/album/"+$routeParams.id)
.then(function (response) {
$scope.product = response.data.msg.album;
});
});
加载http://localhost/或http://localhost/#rock
时,一切正常但是,当我尝试加载http://localhost/#album/1或http://localhost/#/album/1时,我在Chrome调试器的网络标签中看到有两个请求:
为什么会发生这样的事情?