我用$locationProvider
從這個url
http://localhost/angular-phonecat/app/#/phones
刪除hashtag #
使用下面的代碼刪除散列#:
phonecatApp.config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) {
$routeProvider.
when('/phones', {templateUrl: 'partials/phone-list.html', controller: 'PhoneListCtrl'}).
when('/phones/:phoneId', {templateUrl: 'partials/phone-detail.html', controller: 'PhoneDetailCtrl'}).
otherwise({redirectTo: '/phones'});
$locationProvider.html5Mode(true);
}]);
和index.html
加入這頭
<base href="/angular-phonecat/app/">
這個工作和我的當前網址是:
http://localhost/angular-phonecat/app/phones
但是,當我直接訪問該url
它沒有顯示,因爲它不調用index.html
文件的網頁。相反,它顯示/app/phones
目錄的內容
我試圖通過創建一個.htaccess
文件還
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^(/index\.php|/img|/js|/css|/robots\.txt|/favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ./index.html [L]
HTTPS編輯迴應: //scotch.io/tutorials/pretty-urls-in-angularjs-removing-the-hashtag 嘗試以上內容 –