Mat*_*nis 4 javascript node.js angularjs
我的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
});
});
Run Code Online (Sandbox Code Playgroud)
相关的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);
}
});
};
Run Code Online (Sandbox Code Playgroud)
小智 7
设置您的快递应用:
app.route('/*').get(function(req, res) {
return res.sendFile(path.join(config.root, 'index.html'));
});
Run Code Online (Sandbox Code Playgroud)