next.js - nextjs:多个孩子被传递给了“x”的“href”,但只支持一个孩子
问题描述
我没有将多个孩子传递给链接,为什么会出现此错误?错误是:“多个孩子被传递给了href
,/post/61703ea640ff7eef1e1e7e75
但只支持一个孩子”
return (
<>
{head()}
<div className="container-fluid"
style={{
backgroundImage: "url( "+ "/images/default.jpg"+ ")",
backgroundAttachment: "fixed",
padding: "100px 0px 75px 0px",
backgroundRepeat: 'no-repeat',
backgroundSize: 'cover',
backgroundPosition: 'center center',
display: 'block'
}}>
<h1 className="display-1 font-weight-bold text-center py-5">MERNCAMP</h1>
</div>
<div className="container">
<div className="row pt-5">
{posts.map((post) => (
<div key={post._id} className="col-md-4">
<Link href={`/post/view/${post._id}`}>
<a>
<PostPublic key={post._id} post={post} />
</a>
</Link>
</div>
))}
</div>
</div>
</>
)
解决方案
我看不出你的代码有什么问题。
你确定这就是它在你的源文件中的写法吗?如果在<Link>
和<a>
标签之间有空格,通常会发生此错误。
例子:
...
{posts.map((post) => (
<div key={post._id} className="col-md-4">
<Link href={`/post/view/${post._id}`}> <a>
<PostPublic key={post._id} post={post} />
</a></Link>
</div>
))}
您会看到标签之间的空格<Link href={`/post/view/${post._id}`}> <a>
推荐阅读
- python - 如何在 apache livy 中使用 python 脚本提交 jar?
- cmake - 从 makefile 到 Cmake - stm32
- postgresql - 如何从 jsonb 的数组字段中具有 jsonb 嵌套字段的 postgresql 中过滤数据?
- ruby - 无法在 mac 上安装 tiny_tds
- consensus - 在 Ubuntu 16.04 上运行的 Sawtooth 上的 Devmode-engine-rust
- javascript - 我正在使用搜索栏,但我想为其添加预设网址
- java - 用于接口的 Java 类型转换
- google-apps-script - 更改特定单元格时发送电子邮件
- flutter - 如何在颤振应用程序中编辑文本?
- javascript - 在 100 个问题的测验中,questionsArray 被映射,那么如何轻松存储问题、选定的选项和问题的答案?