简体   繁体   中英

What html element to use for react root dom node?

I would like to create an app using semantic html. The app will have header, navigation, main area, footer, and side bar.

The app uses react, so there is an index.js and index.html. This is where react renders an element into the root DOM node.

index.js

 render(<App />, document.getElementById('root'))

index.html

<!DOCTYPE html>
<html lang="en">
  <head>
    <title>My Title</title>
  </head>
  <body>
    //<div id="root"></div>
    // <main id="root"></main>
    // <section id="root"></section>
  </body>
</html>

I expect the app to produce something similar to:

<some root node>
    <header>
    <nav>
    <main>
    <aside>
    <footer>

Since React requires a root node, what element type should that be (what is the most semantically correct)? The root node is inside index.html, therefore a fragment will not solve the problem. I've commented out a few ideas inside index.html which are div, main, and section.

<main> is supposed to relate to the dominant part of the content. If you wish to have navigation, header and/or sidebar and things like that it seems more apropriate to use a div for the App and use the <main> tag for the main content on the page.

并没有真正的区别,但是官方文档使用<div>

You can aldo uso document.body if you prefer. It does not have a particular relevance if you have only a SPA in your page.

You can use main tag for the root and after that use section tag for the respective sections.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM