Home > Net >  TypeError: Object(..) is not a function React-Router v6
TypeError: Object(..) is not a function React-Router v6

Time:02-20

I'm new to React, so when I try to use React-Router <BrowserRouter> I get this error whenever I delete it, the app works just fine I'm using React-router v6 here is the error error

My index.js index.js file

i'm using

"react": "^16.6.3", "react-dom": "^16.6.3", "react-router-dom": "^6.2.1"

thanks in advance

CodePudding user response:

use try it:

ReactDom.render(
<>
 <App/>
</>
,document.getElementById("root"))

CodePudding user response:

After many searching, I figured out that the problem was with my React version 16.6 as react router v6 depends heavily on React Hooks which was introduced starting from React v16.8, so I had to either upgrade my react version or downgrade my React router to v5, which I did and worked just fine. react router docs

source: react router docs https://reactrouter.com/docs/en/v6/upgrading/v5

CodePudding user response:

try it


import {
  BrowserRouter,
  Routes,
  Route
} from "react-router-dom";

ReactDom.render(
<BrowserRouter>
    <Routes>
       <Route path="/" element={<App />}></Route>
      </Route>
    </Routes>
  </BrowserRouter>
,document.getElementById("root"))
  • Related