Skip to content

Commit 56d4496

Browse files
committed
don’t create browserHistory on the server
if you simply `require(‘react-router’)` on the server you get an error, because the singleton is actually created. maybe we should export a memory history?
1 parent bc716cc commit 56d4496

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

modules/browserHistory.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
import useRouterHistory from './useRouterHistory'
22
import createBrowserHistory from 'history/lib/createBrowserHistory'
33

4-
export default useRouterHistory(createBrowserHistory)()
4+
const canUseDOM = !!(
5+
typeof window !== 'undefined' && window.document && window.document.createElement
6+
)
7+
8+
let history
9+
10+
if (canUseDOM) {
11+
history = useRouterHistory(createBrowserHistory)()
12+
}
13+
14+
export default history

0 commit comments

Comments
 (0)