首页 > Web开发 > 详细

angular 去掉url里面的#

时间:2017-06-07 19:34:30      阅读:430      评论:0      收藏:0      [点我收藏+]

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

        # Dont 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里面的#

原文:http://www.cnblogs.com/cynthia-wuqian/p/6958557.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!