-
-
Notifications
You must be signed in to change notification settings - Fork 10.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Does react-router v4 support Hot Module Replacement #4572
Comments
It should, yes. Though I don't know anyone actually doing it yet. You can be the pioneer :) The blocker before was that all of our configuration was specified up front in one spot. But now that our API is Just Components™ anything that you can do with other components you should be able to do with React Router. Please give it a shot and let us know how it goes. |
@helfi92 @mjackson can confirm it is working, I'm using edit: code sample https://gist.github.com/hampusohlsson/9b5ab224f2856b7446892cff0576e78d |
@hampusohlsson @mjackson That's right, it worked liked a charm :) |
Does it work if you're using lazy loaded routes? |
@rclai It should work. The lazy loaded library seems to use // App.js
// ...
const Foo = asyncComponent(() => System.import('./components/Foo').then(module => module.default));
const Bar = asyncComponent(() => System.import('./components/Bar').then(module => module.default));
const Home = asyncComponent(() => System.import('./components/Home').then(module => module.default));
const App = () => (
<Router>
<div className="App">
<ul>
<li><Link to="/">Home</Link></li>
<li><Link to="/foo">Foo</Link></li>
<li><Link to="/bar">Bar</Link></li>
</ul>
<Route exact path="/" component={Home} />
<Route path="/foo" component={Foo} />
<Route path="/bar" component={Bar} />
</div>
</Router>
);
// ... // asyncComponent.js
import React from 'react';
const asyncComponent = getComponent => class AsyncComponent extends React.Component {
constructor(props) {
super(props);
this.Component = null;
this.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;
}
};
export default asyncComponent; |
I created react-router-starter, a starter kit, that uses react-router v4 + router code splitting + hot module replacement. Feel free to use. |
Does
react-router
v4 support Hot Module Replacement withreact-hot-loader
v3? I can't seem to find any documentation on that. If someone can help, I'd be willing to update the docs.The text was updated successfully, but these errors were encountered: