forked from aspnet/JavaScriptServices
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboot-server.jsx
More file actions
23 lines (20 loc) · 816 Bytes
/
Copy pathboot-server.jsx
File metadata and controls
23 lines (20 loc) · 816 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import React from 'react';
import { renderToString } from 'react-dom/server';
import { match, RouterContext } from 'react-router';
import { routes } from './components/ReactApp';
React;
export default function renderApp (params) {
return new Promise((resolve, reject) => {
// Match the incoming request against the list of client-side routes
match({ routes, location: params.location }, (error, redirectLocation, renderProps) => {
if (error) {
throw error;
}
// Build an instance of the application
const app = <RouterContext {...renderProps} />;
// Render it as an HTML string which can be injected into the response
const html = renderToString(app);
resolve({ html });
});
});
}