Skip to content
This repository has been archived by the owner on Apr 20, 2023. It is now read-only.

Handle scrolling to hash on page transition #38

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

nwalters512
Copy link
Member

Browsers only automatically scroll to the URL hash on page load. Since we're doing client-side transitions, we need to handle that ourselves. Normally, Next.js would take care of that for us: https://github.com/zeit/next.js/blob/0b496a45e85f3c9aa3cf2e77eef10888be5884fc/packages/next/client/index.js#L112. However, since we have transitions, the element with the ID referenced by the hash doesn't actually exist when the page change "completes" from the perspective of Next.js, the automatic scrolling fails. This PR will attempt to scroll to the element referenced by the hash as soon as we know that the page is in the DOM after it starts transitioning in.

Fixes #35.

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

Successfully merging this pull request may close these issues.

Anchors (hash part) in urls are ignored, no scrolling takes place
1 participant