Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

anchor detection if the link also contains a path fails #9

Closed
Nemo64 opened this issue Sep 9, 2019 · 1 comment
Closed

anchor detection if the link also contains a path fails #9

Nemo64 opened this issue Sep 9, 2019 · 1 comment

Comments

@Nemo64
Copy link

Nemo64 commented Sep 9, 2019

https://github.com/wessberg/scroll-behavior-polyfill/blob/45593dcfc35f98b64230579eb01ac821c5d9f67d/src/patch/anchor/catch-navigation.ts

The catch-navigation currently looks if a link is clicked with href="#anchor" but it will never catch a link to the current page using href="/url/to/current/page#anchor" because only the attribute value is considered and only if it contains nothing else.

The detection for a link pointing to the current page is actually fairly simple:

const link = e.target;
const pointsToCurrentPage =
       link.origin === location.origin
    && link.pathname === location.pathname
    && link.search === location.search;

const hash = link.hash

Here is a reproduction: https://jsfiddle.net/ey087v3o/ (tested in safari and chrome)

@Nemo64 Nemo64 changed the title navigation detection unreliable anchor detection if the link also contains a path fails Sep 9, 2019
@wessberg
Copy link
Owner

wessberg commented Sep 9, 2019

Hey there. Thanks a lot for your bug report and repro. This has been fixed in the latest release (v2.0.12). I took great inspiration from your detection, thanks a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants