【发布时间】:2016-03-12 05:52:30
【问题描述】:
我正在使用带有 $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。
【问题讨论】:
-
这很正常... angular 与 url 的散列部分一起使用,我认为要能够使用 html5 模式,您还应该更改服务器上的一些设置
-
你在头部添加了html base标签吗?
-
是的,我有
标签
标签: angularjs connect-modrewrite