Next.js项目中Next Link组件部分失效问题求助
解决Next.js中仅第一个Link组件可点击,其余失效的问题
你的问题出在那个绝对定位的装饰性模糊背景容器上。它没有设置pointer-events: none,导致这个透明容器覆盖在下方所有Link组件之上,拦截了点击事件——只有第一个不在它覆盖范围内的Link能正常响应。
修复方案
给带有absolute inset-x-0 top-28 transform-gpu overflow-hidden blur-3xl的div添加pointer-events-none类:
import Link from "next/link"; export default function Home() { return ( <main className=""> <div className="relative isolate pt-14 dark:bg-gray-900"> <div className="absolute inset-x-0 top-28 transform-gpu overflow-hidden blur-3xl pointer-events-none" // 新增pointer-events-none aria-hidden="true" > <div className="relative left-[calc(50%-11rem)] aspect-[1155/678] w-[36.125rem] -translate-x-1/2 rotate-[30deg] bg-gradient-to-tr from-[#ff80b5] to-[#9089fc] opacity-30 sm:left-[calc(50%-30rem)] sm:w-[72.1875rem]" style={{ clipPath: "polygon(74.1% 44.1%, 100% 61.6%, 97.5% 26.9%, 85.5% 0.1%, 80.7% 2%, 72.5% 32.5%, 60.2% 62.4%, 52.4% 68.1%, 47.5% 58.3%, 45.2% 34.5%, 27.5% 76.7%, 0.1% 64.9%, 17.9% 100%, 27.6% 76.8%, 76.1% 97.7%, 74.1% 44.1%)", }} /> </div> <Link href='/chat'>click me</Link> <div className="py-12 sm:py-20 lg:pb-40"> <Link href='/chat'>click me</Link> <div className="mx-auto max-w-7xl px-6 lg:px-8"> <div className="mx-auto max-w-2xl text-center"> <h1 className="text-4xl font-bold tracking-tight sm:text-6xl"> Chat with Anyone, anywhere! </h1> <p className="mt-6 text-lg leading-8 text-gray-600 dark:text-gray-300"> You speak your language, they speak their language.{" "} <span className="text-indigo-600 dark:text-indigo-300"> Let AI handle the translation. </span> </p> <div className="mt-10 flex items-center justify-center gap-x-6"> <Link href="/chat" className="rounded-md bg-indigo-600 px-3.5 py-2.5 text-sm font-semibold text-white dark:text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600" > Get started </Link> <Link className="text-sm font-semibold leading-6 text-gray-900 dark:text-gray-300" href="/pricing"> View Pricing <span aria-hidden="true">→</span></Link> </div> </div> <div> </div> </div> </div> </div> </main> ); }
原理说明
- 绝对定位元素默认会捕获鼠标事件,即使它是透明或半透明状态。
pointer-events: none会让元素忽略所有鼠标交互,点击事件会直接穿透到下方的可交互元素(比如你的Link组件)。- 第一个Link能正常点击,是因为它位于这个绝对定位容器的上方(容器设置了
top-28,第一个Link在容器之前渲染,位置更靠上,不在容器覆盖范围内)。
内容的提问来源于stack exchange,提问作者Johnathan Vargas
相关产品推荐
相关产品推荐

