0

I use an angularJS script with a html page. I use this library : https://github.com/oblador/angular-scroll

I use a script provided by this library to have a scroll spy in my url. It works well but if I have a link to redirect to another page and it doesn't reload the page. The url changed but not the content. If I deleted the script the link works.

this is the script :

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();
    }
  });
});

This is plunker with the script : http://plnkr.co/edit/emrTAvTPMKbLUNYi40Xq?p=preview

And the plunker without : http://plnkr.co/edit/xfsAWsLADkW6F98exC4P?p=preview

2 Answers 2

2

You should assign "true" to "html5Mode.requireBase"

relative link

Sign up to request clarification or add additional context in comments.

2 Comments

It's not suffisant but I found the answer :)
oh sorry your response works too. But another problem was solved, when I scroll top, it was jumped to the top of the section.
0

In fact, we don't have to use $location, history is enough :)

The new script :

.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);
      }
    });
  });

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.