react项目报错link is a void element tag and must neither have `children` nor use `dangerouslySetInnerHTML

在写react项目时,无意将Link标签首字母小写了,导致了link is a void element tag...dangerouslySetInnerHTML这样的错误

错误详情:

link is a void element tag and must neither have `children` nor use `dangerouslySetInnerHTML`.
in link (at Category.js:66)
in li (at Category.js:66)
in ul (at Category.js:65)

报错代码如下:

<ul className="breadcrumb">
    <li><link to="/">主页</link><span className="divider"></span></li>
    <li className="active">栏目管理</li>
</ul>

分析:这里的主要原因是link标签的首字母小写导致的,从import语句可以看出Link首字母是大写:import {Link} from "react-router-dom";,改成首字母大写的Link就可以了。

正确代码如下:

<ul className="breadcrumb">
    <li><Link to="/">主页</Link><span className="divider"></span></li>
    <li className="active">栏目管理</li>
</ul>

the end

标签: react Link
热门文章