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

NextIntlLink Does Not Trigger "hashchange" Event on Clicking a Link with Hash/ID #556

Closed
Israeltheminer opened this issue Oct 8, 2023 · 4 comments
Labels
bug Something isn't working unconfirmed Needs triage.

Comments

@Israeltheminer
Copy link

Description

When utilizing NextIntlLink from next-intl/link to navigate between sections of a page using hash links (e.g., #section1), the "hashchange" event is not being triggered as expected. This issue is critical for functionalities that rely on detecting hash changes in the URL, such as scroll-spy utilities, dynamic section highlighting, and single-page applications (SPAs) that need to manage state based on URL hash fragments.

Mandatory reproduction URL (CodeSandbox or GitHub repository)

https://codesandbox.io/p/sandbox/next-intl-bug-template-app-forked-xn388f?file=%2Fsrc%2Fapp%2F%5Blocale%5D%2Fpage.tsx%3A30%2C9

Reproduction description

Steps to reproduce:

  1. Setup Next.js Project
  2. Install Dependencies
  3. Implement NextIntlLink:
  4. Add "hashchange" Event Listener:
  5. Run the Project

Expected behaviour

A function attached to the "hashchange" event is only called when the hash is changed from the browser search bar, but not when a link with a hash is clicked.

@Israeltheminer Israeltheminer added bug Something isn't working unconfirmed Needs triage. labels Oct 8, 2023
@Israeltheminer
Copy link
Author

Just ran a test with the Link component from 'next/link' and it has the same behavior, might explain why this issue exists 🤔

@amannn
Copy link
Owner

amannn commented Oct 9, 2023

Yep, that seems to be the case! Link from next-intl only wraps next/link, therefore we inherit all the functionality from that component. You might want to report this issue upstream.

@amannn amannn closed this as completed Oct 9, 2023
@hypong
Copy link

hypong commented Mar 8, 2024

I am facing the same issue. Anyone knows how to fix that ?

@sayhicoelho
Copy link

Facing the same issue here. Any updates??!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working unconfirmed Needs triage.
Projects
None yet
Development

No branches or pull requests

4 participants