jonaskuske / smoothscroll-anchor-polyfill

⚓ Apply smooth scroll to anchor links, polyfill scroll-behavior
https://jonaskuske.github.io/smoothscroll-anchor-polyfill
MIT License
41 stars 3 forks source link

I can't get it to work in a React NextJS project #47

Closed oahmaro closed 2 years ago

oahmaro commented 3 years ago

I followed every step in you documentation, and i just can't get it to work on a NextJS application

jonaskuske commented 3 years ago

Can you show me a reproduction? I'm afraid this isn't enough information to help.

jonaskuske commented 2 years ago

This happens because Next calls event.preventDefault() on any link click and handles both the navigation and the scroll internally, so smoothscroll-anchor-polyfill can't intercept.

You can try the scroll-behavior-polyfill package, it should work even with 3rd-party code that intercepts and calls .preventDefault() like Next.js does. (but has some other trade-offs)