Netlify - Next.js - Link #

// https://deploy-preview-1--conectatuproposito.netlify.app

I’m having an issue with the links used in Next.js.

The idea is that when I click on a link that has an ID, it should directly navigate to the sections containing that ID.

The problem is that when I click on one of the links that directs to “/conectate#…” , the link only takes me to the beginning of the page, and the ID is no longer present in the URL.

Steps to reproduce the problem:

  1. In the menu, find the text “conectate”, which displays a menu, where you will find the links with ids
  2. A dropdown menu will appear with options numbered according to the Next.js documentation. Components: <Link> | Next.js
  3. Despite clicking on any of the options, all of them only take me to the beginning of the page and not to the corresponding section.

I would greatly appreciate any help to resolve this issue. Thank you!

Hi @Revione :wave:t6: ,

Welcome to the Netlify support forums! So I checked out your site and I see this in your console.

Does your code looking similar to:

// This will navigate to the section with the ID 'contact'.
<Link href="/#contact">CONTACT US</Link>

Also can you share your src please?This seems like an issue with your code and not with Netlify directly.

Hi @SamO,

Of course, here I share a screen shoot

sorry, but these are the links you find in the menu that pops up after the “conectate” menu option hover.

Hi @SamO, Were you able to reproduce the problem?

Looks like a Next.js issue: Link with hash doesn’t seem to work in next13 · Issue #42157 · vercel/next.js (github.com)

As fas as Netlify is concerned, if you directly access the URL: Conecta tu proposito (deploy-preview-1–conectatuproposito.netlify.app) it works, so I don’t think there’s anything happening wrong from Netlify’s end.

There are numerous issues that need attention here.

The first problem occurs when a link is clicked, resulting in an unnecessary page reload, which should be avoided since Next works without a hard reload.

The second issue involves links with an ID that fail to direct users to the correct destination.

Lastly, when a new tab is opened, the specified ID in the URL correctly leads to the intended destination, but it doesn’t work on the same page.

Let’s collaborate to effectively address these problems.

I don’t believe the issue is originating from Next.js. You can verify this by checking out the Vercel deploy, where the problems I explained earlier do not exist.

Is there someone who can check this problem and find the reason? It looks like a significant issue that needs attention.

Netlify: https://deploy-preview-1--conectatuproposito.netlify.app
Vercel: https://ctp-one.vercel.app

repository

Does this happen if you downgrade Next.js < 13.4? We have an issue in which client-side routing is not working since upgrading to Next.js 13.4.

I had the same issue; using anchor tags directly instead of Link seems to solve it.

1 Like

thanks for sharing this with the community.

Hello there! I recently encountered a problem with my Next.js 14 app. I found that the links were not working on Netlify, but they were working fine on Vercel. To fix this issue, I replaced the Next.js with a regular anchor tag <a,> . After redeploying the project, I was happy to see that it now works perfectly on Netlify. I believe the issue was caused by Netlify not supporting from Next.js.
I shared this because I like Netlify and thought it may help. Thanks for the great free hosting. Netlify is the best!