Cannot read properties of undefined (reading 'location') #9035
Replies: 3 comments 2 replies
-
Did you follow the Step 3 in the guide? import { BrowserRouter } from "react-router-dom";
+import { CompatRouter } from "react-router-dom-v5-compat";
export function App() {
return (
<BrowserRouter>
+ <CompatRouter>
<Switch>
<Route path="/" exact component={Home} />
{/* ... */}
</Switch>
+ </CompatRouter>
</BrowserRouter>
);
} This error would likely come from not having a browser router above it. |
Beta Was this translation helpful? Give feedback.
-
Also verify that your BrowserRouter import is coming from react-router-dom. I had the same location undefined error in CompatRouter. This was because I tried to combine my imports and was importing BrowserRouter from "react-router-dom-v5-compat". It really has to come from "react-router-dom". |
Beta Was this translation helpful? Give feedback.
-
I have the same error, I´m using HashRouter instead of BrowserRoute, but in both cases Cannot read properties of undefined (reading 'location') |
Beta Was this translation helpful? Give feedback.
-
I am halfway through implementing the migration from v5 to v6 and facing this error, somebody pls guide me.
the compat router is showing this error
Beta Was this translation helpful? Give feedback.
All reactions