0
const {history} = this.props;
history.push('/admin/user/create');

The above code is working in React 17 with React Router 5 but in React 18 with react Router 6 it is not working...

Can anyone help me out? I am using class-based components.

F. Müller
  • 3,969
  • 8
  • 38
  • 49
  • Does your app build? Do you get an error? – Mario Perez Mar 20 '23 at 14:04
  • Since react router v6 history changed to navigation : https://stackoverflow.com/a/63921034/8100188 – Afik Habaz Mar 20 '23 at 14:07
  • RRDv6 introduced many changes. I'd recommend you start with the [Getting Started](https://reactrouter.com/en/main/start/overview) and [Upgrading from v5](https://reactrouter.com/en/main/upgrading/v5) guides to catch up. – Drew Reese Mar 20 '23 at 15:47

1 Answers1

-1

Since react router v6 history changed to navigate : https://stackoverflow.com/a/63921034/8100188

I don't use class components but i found this for class components : https://stackoverflow.com/a/61612431

From the Docs: https://reactrouter.com/en/main/components/navigate

I've made a little research and what i found out is that in react router v6 they expect you to wrap your class components in a functional components where you can pass hooks as props as much as you'd like .

If you need more information: https://github.com/remix-run/react-router/issues/8146

Afik Habaz
  • 55
  • 12