React-router: ServerRouter - Invariant Violation: Browser history needs a DOM

Created on 13 Oct 2016  路  3Comments  路  Source: ReactTraining/react-router

Version

4.0.0-alpha.4

Test Case

Following - https://react-router.now.sh/ServerRouter

Steps to reproduce

Following - https://react-router.now.sh/ServerRouter

Expected Behavior

static markup being displayed in browser

Actual Behavior

~/react-app/node_modules/invariant/invariant.js:49
    throw error;
    ^

Invariant Violation: Browser history needs a DOM
    at invariant (~/react-app/node_modules/invariant/invariant.js:42:15)
    at createBrowserHistory (~/react-app/node_modules/history/createBrowserHistory.js:51:102)
    at History.setupHistory (~/react-app/node_modules/react-history/History.js:43:20)
    at History.componentWillMount (~/react-app/node_modules/react-history/History.js:50:10)
    at ~/react-app/node_modules/react/lib/ReactCompositeComponent.js:347:23
    at measureLifeCyclePerf (~/react-app/node_modules/react/lib/ReactCompositeComponent.js:74:12)
    at ReactCompositeComponentWrapper.performInitialMount (~/react-app/node_modules/react/lib/ReactCompositeComponent.js:346:9)
    at ReactCompositeComponentWrapper.mountComponent (~/react-app/node_modules/react/lib/ReactCompositeComponent.js:257:21)
    at Object.mountComponent (~/react-app/node_modules/react/lib/ReactReconciler.js:47:35)
    at ReactCompositeComponentWrapper.performInitialMount (~/react-app/node_modules/react/lib/ReactCompositeComponent.js:370:34)

Most helpful comment

ServerRouter replaces BrowserRouter. I'm guessing your <App> has a <BrowserRouter> inside it. On the server wrap your app in <ServerRouter>, in the client wrap it in <BrowserRouter>.

All 3 comments

ServerRouter replaces BrowserRouter. I'm guessing your <App> has a <BrowserRouter> inside it. On the server wrap your app in <ServerRouter>, in the client wrap it in <BrowserRouter>.

ahh, I see, I have been following the example too blindly, side effect of copy paste. Didn't realize Router is referring to BrowserRouter

import Router from 'react-router/BrowserRouter';

Thanks!

It's called <StaticRouter> now, not <ServerRouter>.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wzup picture wzup  路  3Comments

mr-e- picture mr-e-  路  3Comments

nicolashery picture nicolashery  路  3Comments

davetgreen picture davetgreen  路  3Comments

alexyaseen picture alexyaseen  路  3Comments