首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >警告: validateDOMNesting(…):<a>不能作为<a>的后代出现

警告: validateDOMNesting(…):<a>不能作为<a>的后代出现
EN

Stack Overflow用户
提问于 2019-04-11 13:40:47
回答 3查看 44.4K关注 0票数 28

我正在尝试在创建-重新应用程序.In中将react-router与reactstrap一起使用我需要为reactstrap使用状态的路由页面,因此我将路由器从变量转换为类。我收到以下警告:警告: validateDOMNesting(...):

我不知道该怎么做,我需要用reactstrap设置路由器导航的样式,所以我按照你下面看到的做了。

有很多原因导致这个方法不起作用:

代码语言:javascript
运行
复制
anywords
代码语言:javascript
运行
复制
(a bunch of li not relevant)

          
            
            
                anywords
              
(then just more of the above)


other than a couple of li coming close to each other at random times and me having to refresh the page sometimes instead of the normal behaviour (auto refresh ) and the warning message i get in the console ,nothin bad happens but when i read about this issue i found out that i shouldn't do it.
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2019-04-11 13:56:52

这是导致错误的代码,

代码语言:javascript
运行
复制
anywords

它被转换为,

所以你得到了错误,

代码语言:javascript
运行
复制
Warning: validateDOMNesting(…):  cannot appear as a descendant of

要解决这个问题,只需使用以下方法之一,

代码语言:javascript
运行
复制
anywords

或者,

代码语言:javascript
运行
复制
anywords
票数 46
EN

Stack Overflow用户

发布于 2019-09-15 09:23:38

添加

将属性(以前称为componentClass)添加到原始NavLink以保持样式不变,同时使警告保持静音。

https://react-bootstrap.netlify.com/components/navs/#nav-link-props

或者

查看屏幕截图

原件:

新增:

票数 16
EN

Stack Overflow用户

发布于 2021-02-28 18:52:54

我想提出一个替代方案,它不仅能解决你的问题,而且能给你想要的结果。无论如何,其他人也像我一样偶然发现了这篇文章。

使用react路由器dom提供的Link jsx元素,但添加

为它干杯。这将为您提供react strap正在使用的NavLink jsx的样式。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55625431

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档