harakiri
harakiri

Reputation: 153

How to redirect from redux (w/ react router v6)?

With react-router 5 I used library - react-connected-router to make redirect from redux store. This library doesnt work with react router 6. How I can implement this?

I can just put navigate from useNavigate to payload and then in store use it. But I think it's not good decision. What can you recommend?

Upvotes: 0

Views: 1105

Answers (2)

aleEspinosaM
aleEspinosaM

Reputation: 444

wrap it in a function

let history = useHistory();

const myActions = () => {
 dispatchAction1()
 dispatchAction2()
 history.push("/MY_ROUTE")
}

Upvotes: 0

Lars Vonk
Lars Vonk

Reputation: 738

Can't you just navigate after you have dispatched your action to redux? Then you keep your navigation strictly to ReactComponents

Upvotes: 3

Related Questions