我尝试了其他帖子中有关删除片段标识符 (#) 的所有内容。使用 # 标识符一切正常,但这对我的项目来说将是一个很好的改进。
- 我配置了 $locationProvider 并将 html5Mode 设置为 true
<base href="app" />
在我的 index.html 中设置也试过了<base href="/" />
。我用了<base href="/" />
- 不设基地
requireBase: false
。 $locationProvider.html5Mode(true)
正如有人建议的那样,检查浏览器if(window.history && window.history.pushState)
对 html5 历史 API 的支持- 我按照其他人的建议在 web.config 中编写了一条规则。
- 我用谷歌搜索后尝试了所有我能找到的东西。
我收到此错误:
angular.js:13708 错误:无法在“历史”上执行“pushState”:无法在源为“ http://localhost ”的文档中创建URL 为“ http://sales/?_ijt=d1r1ladp5ro1tvflefsdpnfvd4 ”的历史状态对象:52471 ' 和 URL ' http://localhost:52471/BeerbayCRM/BeerbayCRM/app/index.html?_ijt=d1r1ladp5ro1tvflefsdpnfvd4 '。
请参阅可用环境变量列表非常感谢您的帮助!谢谢你。
这是我的代码:
app.config(['$routeProvider', '$locationProvider', '$httpProvider',
function($routeProvider, $locationProvider) {
$routeProvider
.when('/', {
templateUrl: "views/productsView.html"
})
.when("/products", {
templateUrl: "views/productsView.html"
})
.when("/sales", {
templateUrl: "views/salesView.html"
})
.when("/charts", {
templateUrl: "views/chartsView.html"
})
.otherwise({
templateUrl: "views/productsView.html"
});
if (window.history && window.history.pushState) {
$locationProvider.html5Mode({
enabled: true
});
}
}
])
.controller("routeCtrl", function($scope, $location) {
$scope.setRoute = function(route) {
$location.path(route);
}
});
<!DOCTYPE html>
<html ng-app="myApp">
<head>
<!--.....all the dependencies are here.....-->
<base href="app" />
</head>
<body ng-controller="myAppCtrl">
<div class="navbar navbar-inverse">
<a class="navbar-brand" href="#">Beerbay</a>
</div>
<div ng-controller="routeCtrl" class="col-sm-1">
<a ng-click="setRoute('products')" class="btn btn-block btn-primary btn-lg">Products</a>
<a ng-click="setRoute('sales')" class="btn btn-block btn-primary btn-lg">Sales</a>
<a ng-click="setRoute('charts')" class="btn btn-block btn-primary btn-lg">Charts</a>
</div>
<ng-view/>
</body>
</html>
更新:在我在与 WebStorm 使用不同的节点服务器中启动应用程序后,它部分工作。在我点击刷新页面后,我在页面上只收到一条短消息:“Cannot GET /...__partial view name*”