我的 Angular 应用程序中有一个搜索功能,执行时会点击我的 API 来获取结果,然后使用以下命令重定向用户$location.url
。一切都很好......直到我尝试重新加载结果页面。当我这样做时,我得到一个Cannot GET /search/[search-term]
信息。
应用程序.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);
}
});
};
设置您的 Express 应用程序:
app.route('/*').get(function(req, res) {
return res.sendFile(path.join(config.root, 'index.html'));
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)