我在一個使用以下項目的項目中工作:反應(yīng)/反應(yīng)-dom@16.9.0@loadable/組件樣式組件反應(yīng)路由器dom該應(yīng)用程序呈現(xiàn)服務(wù)器端和客戶端。我正在使用@loadable/component這種方式動態(tài)代碼拆分。路由器.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加載頁面時,此錯誤出現(xiàn)在控制臺上,頁面似乎閃爍了一秒鐘。react-dom.development.js:546 Warning: Did not expect server HTML to contain a <div> in <main>.當我檢查雙方(服務(wù)器/客戶端)的輸出時,它們是相同的。當我@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似乎與此有關(guān),@loadable/component但我不是 100% 確定。
沒想到服務(wù)器 HTML 在 <main> 中包含一個 <div>
喵喵時光機
2021-09-30 10:58:07