Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

browserHistory undefined with React Router 2.00 release candidates

With React Router 2.0.0rc1-5 I have been getting browserHistory as undefined after import:

import { browserHistory } from 'react-router'

The package seems to be installed correctly, but regardless of the version and whether on server or client, I have gotten the same result.

Maybe this a known bug?

like image 476
hoodsy Avatar asked Nov 09 '22 21:11

hoodsy


1 Answers

See useRouterHistory: https://github.com/rackt/react-router/blob/master/upgrade-guides/v2.0.0.md#using-custom-histories

I'm using this in server-side:

import {Router, RouterContext, match, useRouterHistory} from 'react-router';
import {createMemoryHistory} from 'history';

// ...
const appHistory = useRouterHistory(createMemoryHistory)({});
const component = (
  <Provider store={store} key="provider">
    <Router routes={routes} history={appHistory} />
  </Provider>
);
like image 191
Antonio Presto Avatar answered Nov 15 '22 14:11

Antonio Presto