首页 > 代码库 > angular 去掉url里面的#
angular 去掉url里面的#
1.适合客户端的方法,但是页面不能刷新,一刷新就404
(1)在index.html里添加
<base href=http://www.mamicode.com/"/">
(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>
angular 去掉url里面的#
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。