@@ -19,10 +19,18 @@ const morgan = require('morgan');
1919import React from 'react' ;
2020import { renderToString } from 'react-dom/server' ;
2121import moment from 'moment' ;
22- import { StaticRouter } from 'react-router' ;
22+ import {
23+ StaticRouter ,
24+ Switch ,
25+ Route
26+ } from 'react-router' ;
2327import { Provider } from 'react-redux' ;
2428import configureStore from '../../../app/redux/store/configureStore' ;
2529import App from '../../../app/containers/app/App' ;
30+ import ScrollToTop from '../../../app/components/scrollToTop/ScrollToTop' ;
31+ import Login from '../../../app/views/login' ;
32+ import PageNotFound from '../../../app/views/pageNotFound/PageNotFound' ; // not connected to redux (no index.js)
33+ import LogoutRoute from '../../../app/components/logoutRoute/LogoutRoute' ;
2634
2735
2836const DOCS_PATH = '../../../../docs' ;
@@ -47,7 +55,7 @@ app.use(morgan('combined'));
4755
4856app . use ( '/assets' , express . static ( path . resolve ( __dirname , DOCS_PATH , 'public/assets/' ) ) ) ;
4957
50- // IMPORTANT: '/*' and not '/'
58+ // IMPORTANT: '/*' and not '/'
5159// since you want browser refresh (= first render) to work from any route of the application
5260app . get ( '/*' , serverRender ) ;
5361
@@ -104,7 +112,7 @@ async function serverRender(req, res) {
104112 const response = await fakeFetch ( ) ;
105113 const { info } = response ;
106114 const currentTime = moment ( ) . format ( ) ;
107- const currentState = store . getState ( ) ;
115+ const currentState = store . getState ( ) ;
108116
109117 const currentViewsState = currentState . get ( 'views' ) ;
110118 const updatedViewState = currentViewsState
@@ -131,7 +139,14 @@ async function serverRender(req, res) {
131139 < StaticRouter
132140 location = { location }
133141 context = { context } >
134- < App />
142+ < ScrollToTop >
143+ < Switch >
144+ < Route exact path = "/login" component = { Login } />
145+ < App />
146+ < LogoutRoute path = "/logout" />
147+ < Route component = { PageNotFound } />
148+ </ Switch >
149+ </ ScrollToTop >
135150 </ StaticRouter >
136151 </ Provider >
137152 ) ;
@@ -163,15 +178,15 @@ async function serverRender(req, res) {
163178 // .then(
164179 // ({ info }) => {
165180 // const currentTime = moment().format();
166- // const currentState = store.getState();
167-
181+ // const currentState = store.getState();
182+
168183 // const currentViewsState = currentState.get('views');
169184 // const updatedViewState = currentViewsState
170185 // .set('somePropFromServer', info)
171186 // .set('serverTime', currentTime);
172187
173188 // const preWarmedState = currentState.set('views', updatedViewState);
174-
189+
175190 // // //JS would be then:
176191 // // preWarmedState = {
177192 // // ...currentState,
@@ -184,7 +199,7 @@ async function serverRender(req, res) {
184199
185200 // // update store to be preloaded:
186201 // store = configureStore(preWarmedState);
187-
202+
188203 // const InitialView = (
189204 // <Provider store={store}>
190205 // <StaticRouter
@@ -228,8 +243,8 @@ function renderFullPage(html, preloadedState = '') {
228243 // </section>
229244 // will throw warning related to: https://stackoverflow.com/questions/34060968/react-warning-render
230245 //
231- // so write this way to fix:
232- // <section id="root">${html}</section>
246+ // so write this way to fix:
247+ // <section id="root">${html}</section>
233248 const indexHtml = {
234249 template : `
235250 <!DOCTYPE html>
0 commit comments