1.适合客户端的方法,但是页面不能刷新,一刷新就404
(1)在index.html里添加
<base href="/">
(2)在app.js的config里,注入$locationProvider,添加
.config(['$locationProvider',function($locationProvider){
$locationProvider.html5Mode('true');
}])
2.服务器端解决方案(要确保apache中已安装rewrite模块)
<VirtualHost *:>
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>