Skip to content

Commit 513fdc3

Browse files
authored
Update browser-router.tsx
1 parent 162b9a6 commit 513fdc3

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

src/browser-router.tsx

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,16 +107,25 @@ export default class BrowserRouter extends Router {
107107
this.unlistenHistroy();
108108
}
109109

110+
get elScript() {
111+
if(this.stateFromServer !== null) {
112+
const props = {
113+
id : '__react-router-async',
114+
dangerouslySetInnerHTML: {
115+
__html: `window.__REACT_ROUTER_ASYNC__=${JSON.stringify({ state: this.stateFromServer })};`
116+
}
117+
};
118+
119+
return <script {...props} />
120+
}
121+
}
122+
110123
render() {
111124
return (
112-
<div>
125+
<React.Fragment>
113126
{this.props.children ? this.props.children : <this.state.Component {...this.state.componentProps} />}
114-
{this.stateFromServer !== null ?
115-
<script id="__react-router-async" dangerouslySetInnerHTML={{ __html: `window.__REACT_ROUTER_ASYNC__=${JSON.stringify({
116-
state: this.stateFromServer
117-
})};`}} /> : null
118-
}
119-
</div>
127+
{this.elScript}
128+
</React.Fragment>
120129
)
121130
}
122131
}

0 commit comments

Comments
 (0)