Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

140
Views
TypeError: Cannot read properties of undefined (reading 'location') When Adding Route

The react app was working until I added React Router it showes this error

TypeError: Cannot read properties of undefined (reading 'location')

React App

import { Router, Switch, Route } from "react-router-dom";
function App() {
 return (
   <Router>
     <div className="App">
       <Header />
       <Switch>
         <Route path="/" component={MainPage}></Route>
       </Switch>
     </div>
   </Router>
 );
}

export default App;
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

react-router-dom doesn't export Router instead it exports BrowserRouter so the code should be one of the following

First

import { BrowserRouter, Switch, Route } from "react-router-dom";
      <div className="App">
        <Header />
        <Switch>
          <Route path="/" component={MainPage}></Route>
        </Switch>
      </div>
    </BrowserRouter>

Second

import { BrowserRouter as Router, Switch, Route } from "react-router-dom";
      <div className="App">
        <Header />
        <Switch>
          <Route path="/" component={MainPage}></Route>
        </Switch>
      </div>
    </Router>
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!