mirror of
https://github.com/aspnet/JavaScriptServices.git
synced 2025-12-22 17:47:53 +00:00
Update ReactGrid sample to use newer server-side rendering APIs
This commit is contained in:
25
samples/react/ReactGrid/ReactApp/boot-server.jsx
Normal file
25
samples/react/ReactGrid/ReactApp/boot-server.jsx
Normal file
@@ -0,0 +1,25 @@
|
||||
import React from 'react';
|
||||
import { renderToString } from 'react-dom/server';
|
||||
import { match, RouterContext } from 'react-router';
|
||||
import createMemoryHistory from 'history/lib/createMemoryHistory';
|
||||
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 history = createMemoryHistory(params.url);
|
||||
const app = <RouterContext {...renderProps} />;
|
||||
|
||||
// Render it as an HTML string which can be injected into the response
|
||||
const html = renderToString(app);
|
||||
resolve({ html });
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user