Enable server-side prerendering in React+Redux template

This commit is contained in:
SteveSandersonMS
2016-03-07 15:11:13 +00:00
parent cf7a519919
commit c44ceebc12
10 changed files with 54 additions and 22 deletions

View File

@@ -0,0 +1,24 @@
import './css/site.css';
import 'bootstrap/dist/css/bootstrap.css';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { browserHistory, Router } from 'react-router';
import { Provider } from 'react-redux';
import { syncHistoryWithStore } from 'react-router-redux';
import routes from './routes';
import configureStore from './configureStore';
import { ApplicationState } from './store';
// Get the application-wide store instance, prepopulating with state from the server where available.
const initialState = (window as any).initialReduxState as ApplicationState;
const store = configureStore(initialState);
const history = syncHistoryWithStore(browserHistory, store);
// This code starts up the React app when it runs in a browser. It sets up the routing configuration
// and injects the app into a DOM element.
ReactDOM.render(
<Provider store={ store }>
<Router history={ history } children={ routes } />
</Provider>,
document.getElementById('react-app')
);