Skip to content

Commit b1369d2

Browse files
authored
serialize data on server
1 parent ca551ba commit b1369d2

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/server-router.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as React from 'react';
22
import Router, { initParams, initResult } from './router';
3+
import * as serialize from 'serialize-javascript';
34

45
export default class ServerRouter extends Router {
56
static async init(opts: initParams): Promise<initResult> {
@@ -14,9 +15,9 @@ export default class ServerRouter extends Router {
1415
return (
1516
<React.Fragment>
1617
{this.props.children ? this.props.children : <this.state.Component {...this.state.componentProps} />}
17-
<script id="__react-router-async" dangerouslySetInnerHTML={{ __html: `window.__REACT_ROUTER_ASYNC__=${JSON.stringify({
18+
<script id="__react-router-async" dangerouslySetInnerHTML={{ __html: `window.__REACT_ROUTER_ASYNC__=${serialize({
1819
state: this.state
19-
})};`}} />
20+
}, { isJSON: true })};`}} />
2021
</React.Fragment>
2122
)
2223
}

0 commit comments

Comments
 (0)