1.適合客戶端的方法,但是頁面不能刷新,一刷新就404
(1)在index.html里添加
<base href="/">
(2)在app.js的config里,注入$locationProvider,添加
.config(['$locationProvider',function($locationProvider){
$locationProvider.html5Mode('true');
}])
2.服務器端解決方案(要確保apache中已安裝rewrite模塊)
<VirtualHost *:80> ServerName my-app DocumentRoot /path/to/app <Directory /path/to/app> RewriteEngine on # Don't rewrite files or directories RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^ - [L] # Rewrite everything else to index.html to allow html5 state links RewriteRule ^ index.html [L] </Directory> </VirtualHost>