HMR不会为与create-react-app
init'ed应用程序启用。有一个关于一个人如何可以在这里启用博客文章:http://chrisshepherd.me/posts/adding-hot-module-reloading-to-create-react-appHMR用于创建反应的应用程式内反应,终极版
ReactDOM.render(
<App />,
rootEl
);
if (module.hot) {
module.hot.accept('./App',() => {
const NextApp = require('./App').default;
ReactDOM.render(
<NextApp />,
rootEl
);
});
}
我试图做同样的事情,虽然我已经加入redux
和react-router-redux
进来:
App.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;
routes.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到这个项目?
现在更容易了。请检查:https://stackoverflow.com/a/46830787/2668045 –
现在更容易。请检查: https://stackoverflow.com/a/46830787/2668045 –
现在更容易。请检查: https://stackoverflow.com/a/46830787/2668045 –