remix-run / history

Manage session history with JavaScript
MIT License
8.29k stars 961 forks source link

Use History in redux actions #929

Open SimoNonnis opened 2 years ago

SimoNonnis commented 2 years ago

I am in the process to upgrade to rect-router-6 and getting rid of browserHistory inside my redux /actions folder. I am trying to use history using both ways presented here:

two-ways

but I get an error anyway:

Using own history instance:

own-istance

Importing browser history singleton:

singleton

Does anyone know if I am doing something wrong?

Nantris commented 2 years ago

What's your environment that document is not defined? You can try memory-history

petrloukota commented 2 years ago

Use HistoryRouter instead of BrowserRouter: import { unstable_HistoryRouter as HistoryRouter } from 'react-router-dom'; Then, you will be able to import history global object in redux thunk actions. import history from 'history/browser'; // use history in thunk actions