-
Notifications
You must be signed in to change notification settings - Fork 27k
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
Strange behavior of anchor links #68545
Comments
To navigate to a different URL inside your app, say from "/" to "/menu", you should use the Link element. Like this: But, if what you want is to open/hide an HTML element, you can use a React state to handle the condition, and use Tailwind to animate the state between it. My favorite way is to use the HTML data-* attribute using React state and manage the CSS using Tailwind's data attribute selector For example:
With this approach, you can efficiently create a toggling behavior between 2 CSS conditions. |
I think this is not the problem of Next.js itself. I recommend @MrOxMasTer to close this issue. Instead, you can utilize tools like ChatGPT / Claude AI to help you generate a correct code for this. |
I was interested in building a more fault-tolerant system, rather than using a banal option in the form of useState, which does not work with js disabled... |
I see. I hope you find your answer. |
Hi @MrOxMasTer -- This is an unfortunate side effect of the CSS For reference: There's not much we can do on the Next.js side without potentially breaking a lot more common cases, without the CSS spec changing. |
So the |
It renders an anchor tag. If JavaScript is disabled, it will behave as a regular anchor link. When JavaScript is enabled, the app is progressively enhanced to instead use |
This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Link to the code that reproduces this issue
https://codesandbox.io/p/devbox/next15-anchor-link-698s83
To Reproduce
Normal transitions work on headers for example, but together with target in css, for some reason so laggy and dumb. Something with caching, but it's strange even for caching
Current vs. Expected behavior
Current: The menu does not open using the link
Expected behavior: So that everything opens on time and doesn't lag.
Provide environment information
Which area(s) are affected? (Select all that apply)
Navigation
Which stage(s) are affected? (Select all that apply)
next dev (local)
Additional context
Possible solutions to this problem:
Disable javascript on the client
Replacing the Link component with a regular a tag
But with this variation, then when the Link component is pressed after a, the menu does not close (although maybe the problem here is that I don't fully understand how target works).
The text was updated successfully, but these errors were encountered: