我在一個使用以下項目的項目中工作:反應/反應[email protected]@loadable/組件樣式組件反應路由器dom該應用程序呈現服務器端和客戶端。我正在使用@loadable/component這種方式動態代碼拆分。路由器.tsximport * as React from 'react'import loadable from '@loadable/component'import { Route, Switch } from 'react-router-dom'const NotFound = loadable(() => import('../components/NotFound/NotFound' /* webpackChunkName: "notfound" */))const routes = ( <Switch> <Route component={NotFound} /> </Switch>)export default routes加載頁面時,此錯誤出現在控制臺上,頁面似乎閃爍了一秒鐘。react-dom.development.js:546 Warning: Did not expect server HTML to contain a <div> in <main>.當我檢查雙方(服務器/客戶端)的輸出時,它們是相同的。當我@loadable/component像下面那樣刪除時,它可以工作并且錯誤消失了。路由器無負載.tsximport * as React from 'react'import { Route, Switch } from 'react-router-dom'import NotFound from '../components/NotFound/NotFound'const routes = ( <Switch> <Route component={NotFound} /> </Switch>)export default routes似乎與此有關,@loadable/component但我不是 100% 確定。
沒想到服務器 HTML 在 <main> 中包含一個 <div>
喵喵時光機
2021-09-30 10:58:07