如何配置AngularJS以使用$ location但网址中没有任何html5mode = true或任何#?
将html5mode设置为false - 使$ location.path为空 Plunker:http://plnkr.co/edit/g0G1HTuAdZWJPf2FMUMT
Plunker的代码是:
<!DOCTYPE html>
<html ng-app="MyApp">
<head>
<script src="https://code.angularjs.org/1.4.0-beta.5/angular.js" data-semver="1.4.0-beta.5" data-require="angular.js@*"></script>
<script data-require="angular-route@*" data-semver="1.4.0-beta.5" src="https://code.angularjs.org/1.4.0-beta.5/angular-route.js"></script>
<link href="style.css" rel="stylesheet" />
<script src="script.js"></script>
<base href="/"/>
</head>
<body ng-controller="SiteCtrl">
<h1>Hello {{title}}!</h1>
<div >
Site path: {{path}}
</div>
</body>
</html>
angular.module('MyApp',['ngRoute'])
.config(function($locationProvider) {
$locationProvider.html5Mode(false);
})
.controller('SiteCtrl', function($scope, $location) {
$scope.title = "Bla";
$scope.path = $location.path();
})
以最简单的方式...... 提前谢谢。