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:
- Uncaught Error: _registerComponent(…): Target container is not a DOM element
- React Error: Minified React error #119
- Uncaught TypeError: Failed to execute ‘appendChild’ on ‘Node’: parameter 1 is not of type ‘Node How to Fix
- Difference between getelementsbyname and getelementbyid
- Crypto JS decrypts malformed UTF-8 data
- nodejs Error: Cannot find module ‘ejs‘
- Keep alive in Vue
- iOS Xcode:Failed to create provisioning profile.
- [$ injector:unpr ] Unknown provider:–angular.module () function solution
- Xcode Error: Embedded binary’s bundle identifier is not prefixed with the parent app’s bundle identifier
- How to Configure Inter VLAN Routing on Layer 3 Switches?
- Module parse failed:Unexpectedtoken (1:0)You may need an appropriate loader to handle this file type
- Minifiedreacterror — react error report notes
- Python FileNotFoundError: [Errno 2] No such file or directory: ‘objects/epsilon.pkl
- Relative path and absolute path${ pageContext.request.contextPath }
- Learning from OpenGL
- Attempted import error: ‘injectglobal’ is not exported from ‘styled components’
- Android can’t transfer value when using extras, bundle and intent
- Vue router click the menu bar and the same module reports an error Vue router.esm.js? 2215:2065 Uncaught (in promise) Error