0
我有一個子組件,不需要立即加載我想要拆分的子組件。我試圖通過require.ensure
有條件地加載反應組件。我沒有得到任何控制檯錯誤,但我也沒有看到任何被加載。這裏是我打電話的代碼:React/webpack有條件地返回require.ensure組件(代碼拆分)
renderContentzones() {
if (this.props.display) {
return require.ensure([],() => {
const Component = require('./content-zones/component.jsx').default;
return (
<Component
content={this.props.display}
/>
);
});
}
return null;
}
這只是渲染一個空白屏幕(沒有錯誤)。這在以前工作時,我用import 'displayComponent' from './content-zones/component.jsx'
,只是像你通常會反應,而不是這require.ensure返回它,但。不知道我在這裏做錯了什麼,有沒有想法如何做出這樣的工作?謝謝!
如果你做'console.log(Component)',你在控制檯中看到了什麼?未定義? – Hosar