react-hot-loader: You cannot change ; it will be ignored
Hi, I cannot seem to setup the hot reloading. It actually works, but I keep getting the error in console You cannot change <Router routes>; it will be ignored
This is my router file
import React from 'react';
import ReactDOM from 'react-dom';
import {Provider} from 'react-redux';
import {Router, browserHistory} from 'react-router';
import {syncHistoryWithStore} from 'react-router-redux';
import { getRootNode } from '../../helpers/routing_helpers';
// Components
// Hot reload
import { AppContainer as HotLoaderAppContainer } from 'react-hot-loader';
import AppRoutes from './routes';
export default function (inject: Function, {Store}: IContext) {
const history = syncHistoryWithStore(browserHistory, Store);
const renderApp = (CurrentAppRoutes: any) => {
ReactDOM.render(
<HotLoaderAppContainer>
<Provider store={Store}>
<Router history={history}>
{ CurrentAppRoutes }
</Router>
</Provider>
</HotLoaderAppContainer>,
getRootNode('react-root')
);
};
renderApp(AppRoutes);
if (module.hot) {
module.hot.accept('./routes.jsx', () => {
const NextAppRoutes = require('./routes').default;
renderApp(NextAppRoutes);
});
}
};
And a routes file
import React from 'react';
import {Route, IndexRoute } from 'react-router';
// Components
import Layout from './components/layout';
import HomePage from './components/home_view';
import ProfilePage from '../user/components/profile_view';
const AppRoutes = (
<Route path="/" component={Layout}>
<IndexRoute component={HomePage} />
<Route path="profile" component={ProfilePage} />
</Route>
);
export default AppRoutes;
Would you be able to help please?
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 31 (1 by maintainers)
My “solution” is to override the console.error, and filter the warning out. It’s only included when HMR is enabled.
I think this issue should this be kept open util it’s officially fixed?
Was this officially fixed yet?
If others, like me, encounter this when trying to add hot reloading to your react-router based React project from
create-react-app
, the much simpler solution is to make this change (toindex.js
):The trick is the simplicity of the
module.hot.accept()
and that you need to put make the first block a component instead of a block of<Router>
.All those are temporary solutions, but have you tried adding a key to the Router component, like e.g. here https://github.com/reactjs/react-router/issues/2704#issuecomment-211352123 ? I haven’t tried that myself, but seems to be a good workaround, since the problem is rerendering. I have also seen a variant of this solution with
key={ Math.rand() }
, which is surely wild, but less fuss.@tsaiDavid Any fix for your problem? I have the same issue: console shows this
but my App component is not updated
Any luck on this ?
My Routes file has the following:
If you are having this issue this is most likely due to
createBrowserHistory
being in the same file you accept in the HMR. Since the entire file specified will be reloaded, there will be a new history created on each HMR refresh and you will get the error. The simple solution is to create history in a separate file and import it.This causes whole page re-render not the changed component
Well, @thebuilder, thanks for handing me the plastic bag to put over this this annoyances head. That’s one way to go about it lol. I’d keep this issue open though until an official fix comes along.
@akhayoon where ever you want - i have it in my app.js file.
Yes I tried that and it most certainly helps 😉 But, if you add a different key with module reload, you will lose a state and the whole react-hot-reload is kind of useless then ;/