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

445
Views
In React Router V6, can I still get RouteComponentProps (or access to history and location) in class components?

Background I'm migrating from v4 to v6. Many of my pages are class components, not functional components, and I relied heavily on RouteComponentProps (written with Typescript):

export class UserDashboard extends React.Component<RouteComponentProps> {
  constructor(props){
    super(props);
    this.updateURL = buildURLUpdater(props.history, props.location, ...);
    console.log(props.user);
  }

  onChooseUser = (newUser) => {
    this.setState({
      user: newUser
    }, this.updateURL);
  }

  ...
}

<Switch>
  <Route path="/users">
    <Users focusUser={user} />
  </Route>
</Switch>

Question I know that React Router V6 relies heavily on hooks, but I'm not sure how to get location or history in a class component. Is this still possible?

Why I wrote a handy function that I can run after every setState command that would automatically update the URL and insert a history item without having to navigate. This would be for when I want the current search text to show up in the URL bar as the user types. I used props.location and props.history to do that. So if I can't get route component props anymore, I need a way to grab the history and location object, or whatever its V6 equivalents are, in the constructor of a class.

about 4 years ago · Juan Pablo Isaza
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!