Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I fix error React Routr 6.6 +TypeScript?

I have a problem with using React router 6.6 and Typescript.

I installed React router and added it to Index.js like:

import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';
import { RouterProvider } from 'react-router-dom';
import { router } from './router';

const root = ReactDOM.createRoot(
  ....
);

root.render(
  <RouterProvider router={router}>
    <App />
  </RouterProvider>
);

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

And I’m getting this error:

Type ‘{ children: Element; router: Router; }` is not assignable to
type ‘IintrinsicAttributes & RouterProviderProps’. Property
‘children’ does not exist on type ‘IntrinsicAttributes &
RouterProviderProps’. ts(2322)

enter image description here

How can I fix this issue?

I was expecting to work react router with standard way, but it didn’t work.

>Solution :

The new Data routers work a little differently from the older conventional routers. See Picking a Router for more details on the new Data APIs and syntax. Also check the RouterProvider component docs.

The RouterProvider component takes no children, so remove App as a child component.

root.render(<RouterProvider router={router} />);

If you still need to render App somewhere it’ll need to be moved into the router object you created with createBrowserRouter (or similar).

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading