我在我的Angular應用程序中有一個搜索功能,當它執行時我的API抓取結果,然後使用$location.url
重定向用戶。一切都很好,直到我嘗試重新加載結果頁面。當我這樣做時,我得到一個Cannot GET /search/[search-term]
消息。頁面刷新時角度「無法獲取」路線
app.config.js:
'use strict';
angular.module('gameApp')
.config(function($routeProvider, $locationProvider) {
$routeProvider
.when('/player/:playerId', {
templateUrl: 'player.html'
})
.when('/search/:searchTerm', {
templateUrl: '/app/gmSearchResults/gmSearchResults.html'
});
$locationProvider.html5Mode({
enabled: true,
requireBase: false,
rewriteLinks: false
});
});
相關navbar.controller.js:
vm.getSearchResults = function(searchTerm) {
searchService.resource.getResults({
query: searchTerm
}).$promise.then(function(results) {
if (results.playerId) {
$location.url('/customer/' + results.playerId);
} else {
saveLatest(results);
$location.url('/search/' + searchTerm);
}
});
};
您確定服務器響應index.html當您嘗試加載特定頁面嗎?嘗試關閉html5模式並檢查它。 – 2015-07-20 16:31:20