@@ -2,12 +2,14 @@ import './css/site.css';
22import 'bootstrap' ;
33import * as React from 'react' ;
44import * as ReactDOM from 'react-dom' ;
5+ import { AppContainer } from 'react-hot-loader' ;
56import { Provider } from 'react-redux' ;
67import { ConnectedRouter } from 'react-router-redux' ;
78import { createBrowserHistory } from 'history' ;
8- import routes from './routes' ;
99import configureStore from './configureStore' ;
1010import { ApplicationState } from './store' ;
11+ import * as RoutesModule from './routes' ;
12+ let routes = RoutesModule . routes ;
1113
1214// Create browser history to use in the Redux store
1315const history = createBrowserHistory ( ) ;
@@ -16,11 +18,25 @@ const history = createBrowserHistory();
1618const initialState = ( window as any ) . initialReduxState as ApplicationState ;
1719const store = configureStore ( history , initialState ) ;
1820
19- // This code starts up the React app when it runs in a browser. It sets up the routing configuration
20- // and injects the app into a DOM element.
21- ReactDOM . render (
22- < Provider store = { store } >
23- < ConnectedRouter history = { history } children = { routes } />
24- </ Provider > ,
25- document . getElementById ( 'react-app' )
26- ) ;
21+ function renderApp ( ) {
22+ // This code starts up the React app when it runs in a browser. It sets up the routing configuration
23+ // and injects the app into a DOM element.
24+ ReactDOM . render (
25+ < AppContainer >
26+ < Provider store = { store } >
27+ < ConnectedRouter history = { history } children = { routes } />
28+ </ Provider >
29+ </ AppContainer > ,
30+ document . getElementById ( 'react-app' )
31+ ) ;
32+ }
33+
34+ renderApp ( ) ;
35+
36+ // Allow Hot Module Replacement
37+ if ( module . hot ) {
38+ module . hot . accept ( './routes' , ( ) => {
39+ routes = require < typeof RoutesModule > ( './routes' ) . routes ;
40+ renderApp ( ) ;
41+ } ) ;
42+ }
0 commit comments