A React.js app gives the warning
Warning: validateDOMNesting(...): <a> cannot appear as a descendant of <a>.
See Element > a > ... > a.
What does that mean? How can you prevent it? Are nested links illegal in HTML, HTML5 or React.js?
A React.js app gives the warning
Warning: validateDOMNesting(...): <a> cannot appear as a descendant of <a>.
See Element > a > ... > a.
What does that mean? How can you prevent it? Are nested links illegal in HTML, HTML5 or React.js?
That means:
Is invalid HTML. Browsers will recognize this and turn this into:
React warns you about this because the browser's fix will make the actual DOM different from the virtual DOM, leading to strange bugs when React goes to update stuff.
Heed React's warning and don't nest
<a>
tags.I was also getting this warning for my Navigaion, I was using react-bootstrap to render React Router Link in NavItem.
Fix: Add "componentClass" attribute to render NavItem as
<span>
tag instead of<a>
tag (You can use any other tag name here)My code was
After fix
This also messes up styling, to fix it add following CSS
It means that:
and
and similar constructs are not allowed. They don't make sense anyway.
This isn't something that happens without someone writing code that tries to do it.
You need to find that code and change it.
They are illegal in all versions of HTML. The first DTD for HTML was published as part of HTML 2. It says:
The last part describes what content is allowed inside the element. The
-(A)
part of that means "Except for A elements".HTML 5 is just the 2014 update to HTML. HTML 5.1 came out last year. HTML 5.2 is under development.
React.js is a JavaScript library that generates an HTML DOM. The results are still (sort of) HTML.