网址刷新和从网址中删除#符号后重装不工作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。刷新和重新加载一切都工作正常。请帮忙!!!
答
使用
<base href="/cf">
文件 “头” 部分。
希望这有助于!
答
步骤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]
谢谢。它与Nginx一起工作也很好 –