Nolanus / ngx-page-scroll

Animated scrolling functionality for angular written in pure typescript
https://nolanus.github.io/ngx-page-scroll/
MIT License
476 stars 107 forks source link

Directive doesn't work with routerLink and fragment #403

Closed shhdharmen closed 4 years ago

shhdharmen commented 4 years ago

Hello,

When we use pageScroll directive with [routerLink] and [fragment], it doesn't work.

Please see example on stackblitz: https://stackblitz.com/edit/angular-f2plax

Thanks.

Nolanus commented 4 years ago

Hi @shhdharmen,

that's correct, fragment wasn't considered as an alternative attribute to specify the scroll target besides href, now it is (addressed in 10b8f80). However, there's another problem with the example in your stackblitz: [routerLink]="'.'" does not trigger a navigation event, although the library subscribes to it, as it detects a routerLink to be present. Do you use routerLink like that in your app as well or only in the stackblitz example?

shhdharmen commented 4 years ago

Hi @Nolanus ,

Without [routerLink]="'.'", it fragment won't work. And yes, I am using routerLink like that in my app.

Nolanus commented 4 years ago

Ok, because the current check whether the library is on the correct page doesn't detect the dot-url .:

this.router.isActive(this.router.parseUrl('.'), true) // always false

So I assume that this notation is not supported, and it doesn't trigger a router navigation due to unknown destination path, not because the dot-url is resolved to the current active path.

However, the check this.router.isActive(this.router.createUrlTree([]), true) works and always returns true, indicating that the correct way of navigating to the current route would be [routerLink]="[]".

shhdharmen commented 4 years ago

Thanks.