0

I am new on react-router-dom v6. I want to use BrowserHistory in redux ations. Usually I wrapp my app with BrowserHistory and pass history object.

index.js

root.render(
  <BrowserRouter history={history}>
    <Provider store={store}>
      <App />
    </Provider>
  </BrowserRouter>
)

history.js

import { createBrowserHistory } from 'history'
export default createBrowserHistory()

// Actions
export const createStream = (data) => async (dispatch, getState) => {
  const { userId } = getState().auth

  try {
     const response = await addStream({ ...data, userId })
     dispatch({
       type: STREAM_ADDED,
       payload: { stream: response.data },
     })
    history.push('/')
  } catch (ex) {}
}

When user successfully create streams then I want to navigate user "/" path.

Nazmul
  • 33
  • 5
  • Does this help answer your question? https://stackoverflow.com/a/70000286/8690857 – Drew Reese Dec 13 '22 at 15:35
  • I'd also recommend combining the solution in the link with [redux-first-history](https://github.com/salvoravida/redux-first-history) so you have a redux-connected router to also be able to dispatch navigation actions. I've not tested `redux-first-history` with RRDv6.4+ though, so there might be issues there. – Drew Reese Dec 13 '22 at 15:46

0 Answers0