Cannot Use Images or Divs Inside Links?
Answered
Alligator mississippiensis posted this in #help-forum
Alligator mississippiensisOP
pretty self explanatory, I want to be able to use images & divs inside links. I dont know why even Next.js doesnt allow us to do this, I thought of using a relative container with absolute positioned links to solve this but I feel like I shouldn't need to do that, why does next.js not allow us to do that with link elements?
regular <a> tags work just fine with images and divs but if I use that then next.js complains about regular <a> being unoptimized
regular <a> tags work just fine with images and divs but if I use that then next.js complains about regular <a> being unoptimized
Answered by Alligator mississippiensis
it was using this random old component that I named as Link 💀
12 Replies
can you share the error for:
even Next.js doesnt allow us to do this
Alligator mississippiensisOP
next.js itself doesnt raise an error, however ts does, as well as the linter
and next.js will just not render the elements inside the Link element, it only renders the text
the code for the one on the right:
and next.js will just not render the elements inside the Link element, it only renders the text
the code for the one on the right:
export function TestCta({ url, svg, text }: { url: string; svg: string; text: string }) {
return (
<Link url={url} text={text}>
<Image height={40} src={svg} />
</Link>
);
}
the one on the left is if I use <Link>
the one on the right is if I use <a>
the one on the right is if I use <a>
Alligator mississippiensisOP
this bug / weird behaviour happens even for span elements within the link...
here is how its supposed to look
thanks for clarifing. Can you share the error for:
...raise an error, however ts does, as well as the linter
Alligator mississippiensisOP
wait, I think I know why it happens lol
lol
I am quite confused rn
Alligator mississippiensisOP
it was using this random old component that I named as Link 💀
Answer
Alligator mississippiensisOP
instead of the official next.js's link
oh lol