2016-09-20 85 views
0

我app.js網址刷新和從網址中刪除#符號後重裝不工作angularjs

app.config(['$routeProvider','$locationProvider', function($routeProvider,$locationProvider) { 
    $routeProvider. 
    when('/', { 
     templateUrl: 'interests.html', 
     controller: 'InterestsController' 
    }) 
    .when('/interests',{ 
     templateUrl: 'interests.html', 
     controller: 'InterestsController' 
    }) 
    .when('/subjects',{ 
     templateUrl: 'subjects.html', 
     controller: 'SubjectsController' 
    }) 
    .when('/prequalification',{ 
     templateUrl: 'prequalification.html', 
     controller: 'PreQualificationController' 
    }) 
    .when('/qualification',{ 
     templateUrl: 'qualification.html', 
     controller: 'QualificationController' 
    }) 
    .when('/personalinfo',{ 
     templateUrl: 'personalinfo.html', 
     controller: 'PersonalInfoController' 
    }) 
    .otherwise({ 
     redirectTo : '/interests' 
    }); 
    if(window.history && window.history.pushState){ 
     $locationProvider.html5Mode(true); 
    } 
}]); 

在index.html文件。 index.html文件的路徑:localhost:8080/cf /。所有的其他視圖也駐留將以index.html

<base href="/cf/"> 

.htaccess文件內容(路徑爲.htaccess文件:本地主機:8080/CF/htaccess的)

<ifModule mod_rewrite.c> 
    RewriteEngine on 

    # Don't rewrite files or directories 
    RewriteCond %{REQUEST_FILENAME} -f [OR] 
    RewriteCond %{REQUEST_FILENAME} -d 
    RewriteRule^- [L] 


    RewriteRule^cf/index.html [L] 
</ifModule> 

我的項目文件夾在服務器上的路徑是:localhost:8080/cf。我在其他帖子的stackoverflow的.htaccess文件中有各種規則,但沒有任何工作。即使我重新加載或刷新頁面,我得到404。刷新和重新加載一切都工作正常。請幫忙!!!

回答

0

使用

<base href="/cf"> 

文件 「頭」 部分。

希望這有助於!

1

步驟1:在應用程序配置添加此

if(window.history && window.history.pushState){ 
    $locationProvider.html5Mode(true); 
} 

步驟2:在index.html文件添加此

<base href="/your-app-name"> 

步驟3:添加上根.htaccess文件目錄

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} -f [OR] 
RewriteCond %{REQUEST_FILENAME} -d 
RewriteRule^- [L] 
RewriteRule^index.html [L] 
+0

謝謝。它與Nginx一起工作也很好 –