@@ -2,39 +2,36 @@ import * as React from 'react';
22import { Provider } from 'react-redux' ;
33import { renderToString } from 'react-dom/server' ;
44import { StaticRouter } from 'react-router-dom' ;
5- import { replace } from " react-router-redux" ;
5+ import { replace } from ' react-router-redux' ;
66import { createMemoryHistory } from 'history' ;
77import { createServerRenderer , RenderResult } from 'aspnet-prerendering' ;
88import routes from './routes' ;
99import configureStore from './configureStore' ;
1010
1111export default createServerRenderer ( params => {
1212 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 ( ) ) ;
1816 store . dispatch ( replace ( params . location ) ) ;
1917
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 = { } ;
2221 const app = (
2322 < Provider store = { store } >
24- < StaticRouter context = { context } location = { params . location . path } children = { routes } />
23+ < StaticRouter context = { routerContext } location = { params . location . path } children = { routes } />
2524 </ Provider >
2625 ) ;
27-
28- // Perform an initial render that will cause any async tasks (e.g., data access) to begin
2926 renderToString ( app ) ;
3027
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 } ) ;
3431 return ;
3532 }
3633
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
3835 // We also send the redux store state, so the client can continue execution where the server left off
3936 params . domainTasks . then ( ( ) => {
4037 resolve ( {
0 commit comments