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

130
Views
How to redirect to a class component from another class component in reactjs

I know we use history.push() in functional component and react routing for redirection. But in class component how can we redirect on a button click

function onSubmit(){
console.log("Cannot use usehistory in this function as this is a class component")
}

//Link is not working in below code

<Link to ="/login">
<Button onClick={this.onSubmit}>Submit</Button>
</Link>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

If you want to do it with history you can use withRouter higher order component provided by 'react-router'. You just need to import {withRouter}

import {withRouter} from 'react-router';

and export your Component where the button is as :

export default withRouter(Component);

Now you can access hitory object via props. (this.props.history)

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!