跳到主要内容

服务端渲染

https://github.com/facebook/docusaurus/issues/5273

备注

任何组件引用都要换成require的方式放在BrowserOnly组件内部。(import方式因为代码只能放在顶层,故而会出问题)如下所示

import BrowserOnly from '@docusaurus/BrowserOnly';

function MyComponent(props) {
return (
<BrowserOnly fallback={<div>Loading...</div>}>
{() => {
const LibComponent =
require('some-lib-that-accesses-window').LibComponent;
return <LibComponent {...props} />;
}}
</BrowserOnly>
);
}