angular 去掉url里面的#


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>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM