我能够设置react-hot-loader
以正确捆绑我的客户端js并将更改推送到浏览器并在那里应用([react-router] You cannot change <Router routes>; it will be ignored
警告除外)。
我正在使用自己的服务器koa
,koa-webpack-dev-middleware
和koa-webpack-hot-middleware
来处理webpack和hot。它还使用此代码处理我的应用程序的服务器呈现
export default function *renderReact() {
const history = createMemoryHistory();
const store = makeStore(history);
const [redirectLocation, renderProps] = yield match.bind(null, { routes, location: this.url, history });
if (redirectLocation) {
return this.redirect(redirectLocation.pathname + redirectLocation.search)
}
if (renderProps == null) {
return this.throw(404, 'Not found')
}
const rootElement = (
<Provider store={store} key="provider">
<RouterContext {...renderProps} />
</Provider>
);
this.body = renderApp({
html: yield store.renderToString(ReactDOMServer, rootElement),
state: JSON.stringify(store.getState())
});
}
问题在于我的服务器端代码:hot
仅适用于客户端代码并动态更新更改,但我的服务器代码无法更新,因为在服务器启动时加载的脚本和页面重新加载我没有从服务器更新渲染页面,然后用新客户端代码更新。
并反应警告Warning: React attempted to reuse markup in a container but the checksum was invalid...
问题是:如何处理与服务器上的服务器呈现部分相关的代码更改,而不是在重新启动热负载时重新启动应用程序?