thisissoon / angular-scrollspy

A simple lightweight library for Angular which automatically updates links to indicate the currently active section in the viewport
MIT License
35 stars 15 forks source link

Update href when in view #11

Open mebibou opened 5 years ago

mebibou commented 5 years ago

The elements do get the active class when they are in view, but the href of the url is not updated. Would it be possible to add this as an option?

edoparearyee commented 5 years ago

@mebibou thanks for feedback, that would be a nice feature. Will try to take a look at it when I get a chance.

mebibou commented 5 years ago

FYI to activate this behaviour I am currently using

<sn-scroll-spy-section for="scrollNav" id="a" snInViewport inViewportChange)="inViewport($event, 'a')"></sn-scroll-spy-section>
<sn-scroll-spy-section for="scrollNav" id="b" snInViewport inViewportChange)="inViewport($event, 'b')"></sn-scroll-spy-section>
class Component {
  constructor(private location: Location) {}
  inViewport(inViewport, id) {
    if (inViewport) {
      this.location.go(`#${id}`);
    }
  }
}

I also configured my RouterModule to useHash: false, not sure if it would work otherwise