我正在使用带有 $locationProvider.html5Mode 的 stateProvider:
// Redirect any unmatched url
$urlRouterProvider.otherwise("/cool");
$stateProvider
// Dashboard
.state('cool', {
url: "/cool",
templateUrl: "views/cool.html"
});
$locationProvider.html5Mode(true);
但是当我http://localhost:8080/cool
会得到Cannot GET /cool
错误。http://localhost:8080/
并且http://localhost:8080/#/cool
工作正常。
经过一些研究,我发现问题是由于 grunt connect。所以我添加了 modRoute 以将所有 url 路由到 index.html:
livereload: {
options: {
open: true,
middleware: function (connect) {
return [
modRewrite([
'!\\.\\w+$ /'
]),
但现在的问题是每个 url 像http://localhost:8080/uncool到http://localhost:8080/cool。