AngularJS - 自动向URL添加哈希标记 - 覆盖搜索参数

时间:2013-08-20 22:48:27

标签: javascript url angularjs angular-routing

当我点击quicknav时遇到问题,锚标记会替换我在URL中的搜索参数。

'example.com/search?hash=1234'变为'example.com/search#FAQ'

而不是'example.com/search?hash=1234#FAQ'

我该如何解决这个问题?版本1.1.5

HTML锚标记:

<a href="#{{page.id}}" ng-repeat="page in results.page">{{page.id}}</a>

如果有所不同,我确实启用了HTML5模式:

.config(['$locationProvider', function($locationProvider){
    $locationProvider.html5Mode(true).hashPrefix('!');
}]);

1 个答案:

答案 0 :(得分:0)

我现在正在使用一些hacky解决方法:

<a ng-href="{{resultsHash}}#{{page.id}}" ng-repeat="page in results.page">{{page.id}}</a> 

resultsHash

的值
$scope.resultsHash = "?hash=" + data.hash;

因此,每次使用quickNav链接时,哈希都将包含在路径中。这不是一个理想的解决方案。但它模仿我想做的事情。

相关问题