Ng-route会发出不需要的请求

时间:2016-04-02 13:53:02

标签: angularjs ngroute

每当我更改路线时,我的应用程序都会向服务器发送两个不需要的GET请求。一个获取favicon和另一个index.html文件。

enter image description here

var app = angular.module('myApp', ['ngRoute', 'ngTagsInput']);
	app.config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) {
		$locationProvider.html5Mode(true);			
		$routeProvider.when('/', {
			templateUrl: 'views/profile.html',
			resolve: {
				async: ['$http', function($http) {
					return $http.get('/api/getUserInfo');
				}],
				dialogs: ['$http', function($http) { 	
					return $http.get('/api/dialogs');	
				}]										
			},
			controller: 'ProfileController'
			})
		.when('/friends', {
			template: '<div friends-directive votes="model.user.votes" friends="model.friends"></div>'
		})
		.when('/comment', {
			template: '<div comment-directive></div>'
		})
		.when('/dialogs', {
			template: '<div dialog-directive messages="model.messages" dialogs="model.dialogs" new-messages="model.newMessages"></div>'
		})
		.when('/messages', {
			template: '<div messages-directive messages="model.messages"></div>',
			resolve: {
				async: ['$http', function($http) {
					return $http.get('/api/message'); 
				}]
			},
			controller: 'MessagesController'
		})
		.when('/search', {
			template: '<div search-directive></div>'
		})
		.when('/balance', {
			templateUrl: 'views/balance.html'
			})			
		.when('/users/:username', {
			template: '<div users-directive user-profile="model.userProfile" switcher="switcher(path)" resource="model.resource"></div>',
			resolve: {
				async: ['$http', '$route', function($http, $route) {
					return $http.get('/api/users/' + $route.current.params.username); 
				}]
			},
			controller: 'UsersController' 
		})		
		.otherwise({redirectTo: '/'});
	}]);
	
	app.run(['$http', '$window', function($http, $window){
		var update = function(){
			$http.get('/updatetime')
		};
		setInterval(update, 60 * 1000);
		
		$window.onload = function() {
			update();			
		}
	}])

<base href="/">			

<aside id="aside">
	<div><a href="/"><img src="images/profile.svg"></a></div>
	<div><a href="/friends"><img src="images/users.svg"></a></div>
	<div><a href="/search"><img src="images/search.svg"></a></div>
	<div><a href="/balance"><img src="images/database.svg"></a></div>
	<div><a ng-click="logout()"><img src="images/help.svg"></a></div>
</aside>

我刚注意到这些不需要的请求。其他一切都运转正常。知道发生了什么事吗?

1 个答案:

答案 0 :(得分:0)

修复:我的服务器上没有favicon.ico文件。就是这样!