In react-router v5 i created history object like this:
import { createBrowserHistory } from "history";
export const history = createBrowserHistory();
And then passed it to the Router:
import { Router, Switch, Route, Link } from "react-router-dom";
<Router history={history}>
... my routes
</Router>
I did it for the opportunity to usage history outside of component:
// store action
logout() {
this.user = null;
history.push('/');
}
This way I moved the logic to the store and the components were kept as clean as possible. But now, in react router v6 i cant do the same. I can still navigate using useNavigate() inside my component, but i cannot create a navigate to use its into my store. Is there any alternative?