React return a Component instead of from render

React Router Dom使用報錯:

Warning: Functions are not valid as a React child. This may happen if you return a Component instead of <Component /> from render. Or maybe you meant to call this function rather than return it.
at Routes (http://localhost:3001/static/js/bundle.js:40168:5)
at header
at div
at Router (http://localhost:3001/static/js/bundle.js:40101:15)
at BrowserRouter (http://localhost:3001/static/js/bundle.js:38910:5)
at App

解決:

<Route path=“/home” element={Home} />
改成:
<Route path=“/home” element={<Home />} />

相关文章