我已经执行了$locationProvider.html5Mode(true);
但它没有生效。每当我访问http://example.com
,它都会跳转到http://example.com/#!/
。这里是代码:
var myApp = angular.module('myApp', ['ui.router', 'ui.bootstrap']);
myApp.config(['$qProvider', function ($qProvider) {
$qProvider.errorOnUnhandledRejections(false);
}]);
myApp.config(function($stateProvider, $urlRouterProvider,$locationProvider) {
// For any unmatched url, redirect to EXTRANET home page
$urlRouterProvider.otherwise('/');
// Now set up the states
$stateProvider
.state('listrole', {
url: "/list-role",
views: {
'main-content': {
templateUrl: rootUrl+ 'views/main.html',
controller: 'rolesCtrl'
}
}
})
$locationProvider.hashPrefix('');
$locationProvider.html5Mode(true);
});
更新
我也添加了$locationProvider.hashPrefix('');
,但是没有任何区别。另外告诉你,我在地址栏中输入地址并按回车键。我这样做对吗?浏览器如何发现它不需要从服务器刷新?
更新#2
理想情况下,我希望URL为http://example.com
和http://example.com/#!/list-role
变成http://example.com/list-role
。现在http://example.com/list-role
会给出404错误。
更新#3
我正在使用nginx代理,如果有帮助的话。
更新#4
清除缓存后,现在我可以看到http://example.com
,而不是http://example.com/#!
,但仍然会得到404错误http://example.com/list-role
。