没有为使用create-react-app
. 有一篇关于如何在这里启用它的博客文章:http: //chrisshepherd.me/posts/adding-hot-module-reloading-to-create-react-app
ReactDOM.render(
<App />,
rootEl
);
if (module.hot) {
module.hot.accept('./App', () => {
const NextApp = require('./App').default;
ReactDOM.render(
<NextApp />,
rootEl
);
});
}
我正在尝试做类似的事情,尽管我已经添加redux
和react-router-redux
混合:
应用程序.js
import React from 'react'
import { Provider } from 'react-redux'
import store from './store/store'
import routes from './routes'
const App = (
<Provider store={store}>
{ routes }
</Provider>
);
export default App;
路由.js
import React from 'react';
import { browserHistory, Router, Route } from 'react-router';
import { syncHistoryWithStore } from 'react-router-redux';
import store from '../store/store';
import { AnonymousLayout } from '../layouts';
import { LoginForm } from './Login';
const history = syncHistoryWithStore(browserHistory, store);
export default (
<Router history={history}>
<Route path="/" component={AnonymousLayout}>
<Route path="/login" component={LoginForm} />
</Route>
</Router>
);
index.js
import React from 'react'
import ReactDOM from 'react-dom'
import App from './client/App';
const rootEl = document.getElementById('root');
ReactDOM.render(
App,
rootEl
);
if (module.hot) {
module.hot.accept('./client/App', () => {
const NextApp = './client/App';
ReactDOM.render(
<NextApp />,
rootEl
);
});
}
但是,我只是收到此错误:
Warning: [react-router] You cannot change <Router routes>; it will be ignored
有什么方法可以将 HMR 入侵到这个项目中吗?