0
我想使用AngularJS路由。我使用AngularJS-seed-master作爲默認啓動和路由工作。但是,啓用html5mode後,它停止工作。以下是路由工作時的html代碼;爲什麼在啓用html5mode時這個AngularJS路由被破壞?
<ul class="menu">
<li><a href="#/view1">view1</a></li>
<li><a href="#/view2">view2</a></li>
</ul>
<div ng-view></div>
<script src="lib/angular/angular.min.js"></script>
<script src="lib/angular/angular-route.min.js"></script>
<script src="js/app.js"></script>
<script src="js/services.js"></script>
<script src="js/controllers.js"></script>
<script src="js/filters.js"></script>
<script src="js/directives.js"></script>
當路由工作時,Javscript app.js代碼;
angular.module('myApp', [
'ngRoute',
'myApp.filters',
'myApp.services',
'myApp.directives',
'myApp.controllers'
]).
config(['$routeProvider', function($routeProvider)
{
//configuration for $routeProvider
$routeProvider.when('/view1', {templateUrl: 'partials/partial1.html', controller: 'MyCtrl1'});
$routeProvider.when('/view2', {templateUrl: 'partials/partial2.html', controller: 'MyCtrl2'});
$routeProvider.otherwise({redirectTo: '/view1'});
}])
然後,我啓用html5mode加入這app.js
.config(['$locationProvider', function($locationProvider)
{
$locationProvider.html5Mode(true);
}])
正是在這一點上,AngularJS路由停止工作。我做錯了什麼?在啓用html5Mode之後,AngularJS路由如何工作?
http://stackoverflow.com/a/23311886/189756 [$位置/ HTML5和hashbang模式之間切換/鏈路重寫](的 –
可能重複http://stackoverflow.com/questions/16677528/location-switching -between-HTML5和 - hashbang模式 - 連接 - 重寫) – rvignacio