mobx-react-router
mobx-react-router copied to clipboard
Compatible with Server Side Rendering?
Anyone using this library with their SSR setup? I keep getting
Invariant Violation: Browser history needs a DOM
errors with react-router...
You should use StaticRouter
with MemoryHistory
for SSR.
I've made it work as follows, let me know if that helps
import {Router, StaticRouter, StaticRouterContext} from "react-router";
import { createMemoryHistory } from 'history';
import {syncHistoryWithStore} from "mobx-react-router";
function reactApp(url: string, apollo: ApolloClient<any>, context: StaticRouterContext = {}) {
const memoryHistory = createMemoryHistory();
const history = syncHistoryWithStore(memoryHistory, new RouterStore());
history.replace(url);
return (
<Router history={history}>
<StaticRouter location={url} context={context}>
<Application
apollo={apollo}
/>
</StaticRouter>
</Router>
);
}