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

285
Views
Why is React-router link not working on onClick function
 <Link to="/final-preview">
            <button  onClick={handleSubmit}>
              Final Preview
            </button>
 </Link>

So before the onClick function the Link was working perfectly but after it's not. I'd be really grateful if someone knows some specificity about router link :)

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

You could potentially try useNavigate as a solution instead as

import { useNavigate } from "react-router-dom";

function ThisPage() {
  let navigate = useNavigate();

  const leavePage = () => {
    navigate("/final-preview");
  }
  
  return (
    <div>
      <button onClick = {leavePage}/>
    </div>
  )
}

export default ThisPage;

In the leave page method, you can handle submitting the preview, before navigating to the next link.

Hope this helps.

about 4 years ago · Santiago Trujillo Report

0

Here is example

First Import React Router

import {
  Link as RouterLink,
  Route,
  Routes,
} from "react-router-dom";

Add code

<Link component={RouterLink} to="/final-preview">
      <button  onClick={handleSubmit}>
       Final Preview
       </button>
 </Link>
about 4 years ago · Santiago Trujillo 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!