这与AngularJS 1.0.7 in html5Mode get 404 error when refresh page有关。但是,实际上我在该帖子中描述的问题是固定的,但在此之后,新的错误已经出现。所以,我已将前一个标记为正常,我将解释我的新错误:
总而言之,页面刷新现在正在运行,但是与链接相关的某些功能已停止工作。我发布了一个示例代码:
HTML
<li ng-show="logged" class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" style="padding-top: 10px; padding-bottom: 5px">
<img ng-show="user.mainPhoto" src="//{{S3_BUCKET}}.{{PHOTO_SERVER_URL}}/img/users/{{user.id}}/{{user.mainPhoto.id}}.{{user.mainPhoto.mime}}" style="height: 30px; width: 30px;" class="img-circle"/>
<i ng-hide="user.mainPhoto" class="fa-icon-user" style="font-size: 22px;margin-right: 5px"></i>
{{user.name}}
<span class="badge" style="background-color: rgb(41, 169, 223)" ng-show="userAlerts.length > 0">{{userAlerts.length}}</span>
<b class="caret" style="margin-top: 14px"></b>
</a>
<ul class="dropdown-menu">
<li><a href="#" tabindex="-1" ng-click="goToProfile()">{{'PROFILE' | translate}}</a></li>
<li class="divider"></li>
<li><a tabindex="-1" href="" ng-click="logout()">{{'LOGOUT' | translate}}</a></li>
</ul>
</li>
JS
login.js
$scope.goToProfile = function(){
$location.search({});
$location.path('/user-dashboard');
};
app.js:
angular.module('myApp',['myApp.filters','myApp.services','myApp.directives','myApp.controllers']) .config(['$ routeProvider','$ httpProvider','$ locationProvider',function($ routeProvider,$ httpProvider,$ locationProvider){
// use the HTML5 History API
$locationProvider.html5Mode(true);
$httpProvider.defaults.useXDomain = true;
delete $httpProvider.defaults.headers.common["X-Requested-With"];
$routeProvider.when('/', {templateUrl: 'partials/home.html', controller: 'HomeCtrl'});
$routeProvider.when('/about', {templateUrl: 'partials/about.html', controller: 'AboutCtrl'});
$routeProvider.when('/contact', {templateUrl: 'partials/contact.html', controller: 'HomeCtrl'});
$routeProvider.when('/home', {templateUrl: 'partials/home.html', controller: 'HomeCtrl'});
$routeProvider.when('/user-dashboard', {templateUrl: 'partials/user-dashboard.html', controller: 'UserDashboardCtrl'});
$routeProvider.when('/user-dashboard#tabProfile', {templateUrl: 'partials/user-dashboard.html#tabProfile', controller: 'UserDashboardCtrl'});
$routeProvider.otherwise({redirectTo: '/'});
}])
Nginx配置文件(仅相关部分):
server {
listen 80;
server_name localhost;
#charset koi8-r;
access_log logs/host.access.log;
rewrite_log on;
location / {
root /Users/Rober/Projects/yanpy/dev/yanpy/app;
index index.html index.htm;
try_files $uri $uri/ /index.html =404;
}
当我点击goToProfile的链接时,要导航到用户仪表板,我只是被重定向到索引。注意:对于其他链接或操作正确导航。
答案 0 :(得分:0)
通过删除href =“#”修复它。你必须完全删除它,如果你只是做href =“”它不起作用。