You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Next.js 13页面内锚点跳转失效问题求助

Next.js 单页内锚点跳转失效问题

我想要在单页中实现不同区块的锚点跳转,已参考过相关Stack Overflow问题但无效。以下是我的两次尝试:


第一次尝试:

// app/layout.tsx
<Link href="#home" scroll={false}> Home </Link>
<Link href="#about" scroll={false}> About </Link>

// app/page.tsx
<section id="home" className="min-h-screen">home</section>
<section id="about" className="min-h-screen">about</section>

点击链接时,浏览器开发环境出现错误。


第二次尝试:
我在链接中添加斜杠以指向首页路由:

// app/layout.tsx
<Link href="/#home" scroll={false}> Home </Link>
<Link href="/#about" scroll={false}> About </Link>

// app/page.tsx
<section id="home" className="min-h-screen">home</section>
<section id="about" className="min-h-screen">about</section>

现在点击两个链接都会跳转到页面顶部(home区块),about链接无法滚动到对应区块。


2022年4月12日编辑:
问题似乎与Next的Link组件有关,直接点击开发者工具中生成的a标签可正常滚动到对应区块。


内容的提问来源于stack exchange,提问作者iAmWhy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.14 07:25:22