@@ -19,10 +19,18 @@ const morgan = require('morgan');
19
19
import React from 'react' ;
20
20
import { renderToString } from 'react-dom/server' ;
21
21
import moment from 'moment' ;
22
- import { StaticRouter } from 'react-router' ;
22
+ import {
23
+ StaticRouter ,
24
+ Switch ,
25
+ Route
26
+ } from 'react-router' ;
23
27
import { Provider } from 'react-redux' ;
24
28
import configureStore from '../../../app/redux/store/configureStore' ;
25
29
import 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' ;
26
34
27
35
28
36
const DOCS_PATH = '../../../../docs' ;
@@ -47,7 +55,7 @@ app.use(morgan('combined'));
47
55
48
56
app . use ( '/assets' , express . static ( path . resolve ( __dirname , DOCS_PATH , 'public/assets/' ) ) ) ;
49
57
50
- // IMPORTANT: '/*' and not '/'
58
+ // IMPORTANT: '/*' and not '/'
51
59
// since you want browser refresh (= first render) to work from any route of the application
52
60
app . get ( '/*' , serverRender ) ;
53
61
@@ -104,7 +112,7 @@ async function serverRender(req, res) {
104
112
const response = await fakeFetch ( ) ;
105
113
const { info } = response ;
106
114
const currentTime = moment ( ) . format ( ) ;
107
- const currentState = store . getState ( ) ;
115
+ const currentState = store . getState ( ) ;
108
116
109
117
const currentViewsState = currentState . get ( 'views' ) ;
110
118
const updatedViewState = currentViewsState
@@ -131,7 +139,14 @@ async function serverRender(req, res) {
131
139
< StaticRouter
132
140
location = { location }
133
141
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 >
135
150
</ StaticRouter >
136
151
</ Provider >
137
152
) ;
@@ -163,15 +178,15 @@ async function serverRender(req, res) {
163
178
// .then(
164
179
// ({ info }) => {
165
180
// const currentTime = moment().format();
166
- // const currentState = store.getState();
167
-
181
+ // const currentState = store.getState();
182
+
168
183
// const currentViewsState = currentState.get('views');
169
184
// const updatedViewState = currentViewsState
170
185
// .set('somePropFromServer', info)
171
186
// .set('serverTime', currentTime);
172
187
173
188
// const preWarmedState = currentState.set('views', updatedViewState);
174
-
189
+
175
190
// // //JS would be then:
176
191
// // preWarmedState = {
177
192
// // ...currentState,
@@ -184,7 +199,7 @@ async function serverRender(req, res) {
184
199
185
200
// // update store to be preloaded:
186
201
// store = configureStore(preWarmedState);
187
-
202
+
188
203
// const InitialView = (
189
204
// <Provider store={store}>
190
205
// <StaticRouter
@@ -228,8 +243,8 @@ function renderFullPage(html, preloadedState = '') {
228
243
// </section>
229
244
// will throw warning related to: https://stackoverflow.com/questions/34060968/react-warning-render
230
245
//
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>
233
248
const indexHtml = {
234
249
template : `
235
250
<!DOCTYPE html>
0 commit comments