0

I'm new to NextJS, and I'm working on a page that's under a /security/ path.

On the file /app/security/page.jsx I have a simple link to an anchor tag

<Link href="#data-storage" scroll={false}>Data Storage</Link>

Clicking this link will navigate to /#data-storage instead of /security/#data-storage.

Changing the Link to an "a" works as expected. Why is Link doing this?

pfandrade
  • 2,359
  • 15
  • 25

1 Answers1

0

You can use an absolute URL instead of a relative URL:

<Link href="/security/#data-storage" scroll={false}>Data Storage</Link>

This is because the Link component in Next.js v13 uses the HTML5 History API to navigate between pages

dom1
  • 425
  • 1
  • 2
  • 19