The error message
Uncaught Invariant Violation: A <Router> may have only one child element
at invariant (http://localhost:8111/bundle.js:1071:15)
at Router.componentWillMount (http://localhost:8111/bundle.js:2413:54)
at callComponentWillMount (http://localhost:8111/bundle.js:27042:14)
at mountClassInstance (http://localhost:8111/bundle.js:27135:5)
at updateClassComponent (http://localhost:8111/bundle.js:30309:5)
at beginWork (http://localhost:8111/bundle.js:31265:16)
at performUnitOfWork (http://localhost:8111/bundle.js:34933:12)
at workLoop (http://localhost:8111/bundle.js:34973:24)
at renderRoot (http://localhost:8111/bundle.js:35056:7)
at performWorkOnRoot (http://localhost:8111/bundle.js:35963:7)
The solution
The original demo
ReactDom.render(
<BrowserRouter>
<Nav />
{getRouter()}
</BrowserRouter>,
document.getElementById('app')
)
Resolved Demo (if there are multiple components in The BrowserRouter, add a layer of div to the BrowserRouter)
ReactDom.render(
<BrowserRouter>
<div>
<Nav />
{getRouter()}
</div>
</BrowserRouter>,
document.getElementById('app')
)
As for the reasons, I haven’t studied them in detail yet. If you know some friends, you can communicate with them, or explain them in the comments below. Thank you.
Read More:
- In chome browser, console reports an error but does not display it
- Java uses ZipFile to decompress the zip file and runs normally under Windows. Linux reports an error
- The echo introduced in react reports an error: xaxis “0” not found
- This version of chromedriver only supports chrome version 92 crawler simulates the problem of Google plug-in version when the browser clicks and reports an error
- An error is reported when using react app rewired to start the react project
- Error code 1 error resolution (NPX create react app my app execution reports an error)
- After NPM run dev is running, the browser does not respond and reports an error in. / ~ / Babel loader / lib! / ~ / Vue loader / lib/ selector.js?type=script&in
- The echots in Vue reports an error. After obtaining the DOM element, the chart can be displayed. The console still reports an error
- Hadoop reports an error. Cannot access scala.serializable and python MapReduce reports an error
- Raspberry Pi runs ubuntu-mate and reports Failed to start Load Kernel Modules error countermeasures
- HTML method IE8 reports an error, IE8 jQuery Ajax obtains static resources reports an error, typeerror denies access
- The file server reports an error of 413, and the file uploaded by nginx reports an error of 413 request entity too large
- Lamdba in the studio part reports an error. Observe lamdba reports an error but can run
- webstorm npm install –save –save-exact –loglevel error react react-dom react-scripts has failed.
- Python fbprophet predicts that the code runs with an error
- IIS 7.5, ASP.NET MVC. HTTP error 500 (internal server error), but debugging does not enter the background, the browser only reports 500 errors
- Scrapy runs a crawler with an error importerror: cannot import name suppress
- When Jekyll runs, it will prompt an error. Cannot load such file — webrick (LoadError)
- The browser reported an error ‘stylesheets undefined’‘‘
- The SuperMap webgl browser reported an error. The unzip.wasm file 404