我使用带有html页面的angularJS脚本。我使用这个库:https://github.com/oblador/angular-scroll
我使用此库提供的脚本在我的网址中有一个滚动间谍。 它运作良好,但如果我有一个链接重定向到另一个页面,它不会重新加载页面。网址已更改,但内容未更改。如果我删除了脚本,则链接可以正常工作。
这是剧本:
var myApp = angular.module('app_example', ['duScroll'])
.config(function($locationProvider) {
$locationProvider.html5Mode({
enabled: true,
requireBase: false
})
}).
run(function($rootScope, $location) {
$rootScope.$on('duScrollspy:becameActive', function($event, $element){
//Automaticly update location
var hash = $element.prop('hash');
if (hash) {
$location.hash(hash.substr(1)).replace();
$rootScope.$apply();
}
});
});
的掠夺者
答案 0 :(得分:2)
您应该将“true”分配给“html5Mode.requireBase”
relative link
答案 1 :(得分:0)
事实上,我们不必使用$location
,历史就足够了:)
新剧本:
.run(function($rootScope, $location) {
if(!history || !history.replaceState) {
return;
}
$rootScope.$on('duScrollspy:becameActive', function($event, $element){
//Automaticly update location
var hash = $element.prop('hash');
if (hash) {
history.replaceState(null, null, hash);
}
});
});