There are two pages A and B. I am on page and A and I want a link that takes me from page A to page B and to a specific div
which has the id id
. I tried out various things like
import Link from 'next/link'
<Link href="/about/#about" scroll={true}>
<a>My about text</a>
</Link>
or using useEffect to fetch the hash key in the url and use getElementById
to scroll to that specific section but that isn't working. I am not able to actually fetch the element even after defining use client
on top of the file where I defined the useEffect
. I understand that this problem is related to server side rendering feature of Next.js. How can I handle it for my case?
There are two pages A and B. I am on page and A and I want a link that takes me from page A to page B and to a specific div
which has the id id
. I tried out various things like
import Link from 'next/link'
<Link href="/about/#about" scroll={true}>
<a>My about text</a>
</Link>
or using useEffect to fetch the hash key in the url and use getElementById
to scroll to that specific section but that isn't working. I am not able to actually fetch the element even after defining use client
on top of the file where I defined the useEffect
. I understand that this problem is related to server side rendering feature of Next.js. How can I handle it for my case?
1 Answer
Reset to default -1try without <a>
tag and href as href="/about#about"
/about#about
tried this? – Tushar Shahi Commented Feb 17 at 9:38