@@ -2,39 +2,36 @@ import * as React from 'react';
2
2
import { Provider } from 'react-redux' ;
3
3
import { renderToString } from 'react-dom/server' ;
4
4
import { StaticRouter } from 'react-router-dom' ;
5
- import { replace } from " react-router-redux" ;
5
+ import { replace } from ' react-router-redux' ;
6
6
import { createMemoryHistory } from 'history' ;
7
7
import { createServerRenderer , RenderResult } from 'aspnet-prerendering' ;
8
8
import routes from './routes' ;
9
9
import configureStore from './configureStore' ;
10
10
11
11
export default createServerRenderer ( params => {
12
12
return new Promise < RenderResult > ( ( resolve , reject ) => {
13
- // Create memory history to use in the Redux store
14
- const history = createMemoryHistory ( ) ;
15
- const store = configureStore ( history ) ;
16
-
17
- // Dispatch the current location so that the router knows where to go
13
+ // Prepare Redux store with in-memory history, and dispatch a navigation event
14
+ // corresponding to the incoming URL
15
+ const store = configureStore ( createMemoryHistory ( ) ) ;
18
16
store . dispatch ( replace ( params . location ) ) ;
19
17
20
- const context : any = { } ;
21
-
18
+ // Prepare an instance of the application and perform an inital render that will
19
+ // cause any async tasks (e.g., data access) to begin
20
+ const routerContext : any = { } ;
22
21
const app = (
23
22
< Provider store = { store } >
24
- < StaticRouter context = { context } location = { params . location . path } children = { routes } />
23
+ < StaticRouter context = { routerContext } location = { params . location . path } children = { routes } />
25
24
</ Provider >
26
25
) ;
27
-
28
- // Perform an initial render that will cause any async tasks (e.g., data access) to begin
29
26
renderToString ( app ) ;
30
27
31
- // If there's a redirection, just send this information back to the host application (Maybe improve this?)
32
- if ( context . url ) {
33
- resolve ( { redirectUrl : context . url } ) ;
28
+ // If there's a redirection, just send this information back to the host application
29
+ if ( routerContext . url ) {
30
+ resolve ( { redirectUrl : routerContext . url } ) ;
34
31
return ;
35
32
}
36
33
37
- // Once the tasks are done, we can perform the final render
34
+ // Once any async tasks are done, we can perform the final render
38
35
// We also send the redux store state, so the client can continue execution where the server left off
39
36
params . domainTasks . then ( ( ) => {
40
37
resolve ( {
0 commit comments