updated SSR to create custom GA listener from siteConfig

This commit is contained in:
bill bittner 2018-03-31 18:27:24 -07:00
parent ba01ce8e68
commit 8ef29f2d68
3 changed files with 27 additions and 23 deletions

File diff suppressed because one or more lines are too long

View file

@ -20,19 +20,20 @@ module.exports = (req, res) => {
let context = {};
// customize the reducer by passing in intial state configs
const CustomizedReducers = Reducers(siteConfig);
const CustomizedApp = App(siteConfig);
const MyReducers = Reducers(siteConfig);
const MyApp = App(siteConfig);
const MyGAListener = GAListener(siteConfig);
// create a new Redux store instance
const store = createStore(CustomizedReducers);
const store = createStore(MyReducers);
// render component to a string
const html = renderToString(
<Provider store={store}>
<StaticRouter location={req.url} context={context}>
<GAListener>
<CustomizedApp />
</GAListener>
<MyGAListener>
<MyApp />
</MyGAListener>
</StaticRouter>
</Provider>
);

View file

@ -18,8 +18,9 @@ import Helmet from 'react-helmet';
// configure the reducers by passing initial state configs
const siteConfig = require('siteConfig.js');
const CustomizedReducers = Reducers(siteConfig);
const CustomizedApp = App(siteConfig);
const MyReducers = Reducers(siteConfig);
const MyApp = App(siteConfig);
const MyGAListener = GAListener(siteConfig);
const returnSagaWithParams = (saga, params) => {
return function * () {
@ -35,7 +36,7 @@ module.exports = (req, res) => {
const middleware = applyMiddleware(sagaMiddleware);
// create a new Redux store instance
const store = createStore(CustomizedReducers, middleware);
const store = createStore(MyReducers, middleware);
// create saga
const action = Actions.onHandleShowPageUri(req.params);
@ -50,9 +51,9 @@ module.exports = (req, res) => {
const html = renderToString(
<Provider store={store}>
<StaticRouter location={req.url} context={context}>
<GAListener>
<CustomizedApp />
</GAListener>
<MyGAListener>
<MyApp />
</MyGAListener>
</StaticRouter>
</Provider>
);