使用 webpack2.2.0-rc1 和 react routerv4,并使用这个gist使代码拆分工作,其中说明如下
function asyncComponent(getComponent) {
return class AsyncComponent extends React.Component {
static Component = null;
state = { Component: AsyncComponent.Component };
componentWillMount() {
if (!this.state.Component) {
getComponent().then(Component => {
AsyncComponent.Component = Component
this.setState({ Component })
})
}
}
render() {
const { Component } = this.state
if (Component) {
return <Component {...this.props} />
}
return null
}
}
}
const Foo = asyncComponent(() =>
System.import('./Foo').then(module => module.default)
)
它确实有效,但我使用的是服务器端渲染。因此,在服务器上我需要组件 A,然后在客户端上我 System.import 组件 A。最后,当我访问延迟加载的路由时,我得到了这个反应重用标记警告,因为客户端最初从https://gist.github加载了 null .com/acdlite/a68433004f9d6b4cbc83b5cc3990c194#file-app-js-L21
加载组件 A。
Warning: React attempted to reuse markup in a container but the checksum was invalid. This generally means that you are using server rendering and the markup generated on the server was not what the client was expecting. React injected new markup to compensate which works but you have lost many of the benefits of server rendering. Instead, figure out why the markup being generated is different on the client or server:
(client) CO 0.0.0 </h1></div><!-- react-empty: 6 -
(server) CO 0.0.0 </h1> </div><div data-radium="tru
我怎样才能使这项工作没有错误?