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

156
Views
How to access data from location in react-router-dom 6

Working on a 'forgot password' functionality, I am trying to pass the email data from the 'login page' to the 'forgot password' page through Link.

But when I am trying to access the same in the 'forgot password' page, it is giving me undefined.

Could you please check my syntax?

Below is the code-snippet and the code of the 'login page':

<div className="forget-password-container">
   <div>
       {" "}
       <Link to={{
          pathname: "/forget-password",
          state: formData.email,
       }}>
          <u style={{ textDecoration: "underline" }}>Forgot Password</u>
       </Link>
    </div>
</div>

Forget Password Page:

const ForgetPassword = (props) => {
   // const { email } = (props.location && props.location.state) || {};
   console.log(props?.location?.state);
   return <div>ForgetPassword </div>;
 };
        
export default ForgetPassword;

Please suggest to me how can I access the mail data on the 'forgot password' page

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

With react-router V6 you can use the outlet component and pass a context to another page.

 <Routes>
   <Route path="/login" element={Login}/>
     <Route path="/reset-password" element={ResetPass}/>
</Routes>

const Login = () => {
    ...
    <Outlet context={contextdata} /> // contextdata - data to pass
}


const ResetPass = () => {
    const { contextdata } = useOutletContext<IContext>() // data from Login page

        ...
        <div>{contextdata}</div>
}

Please take a look here: Pass Props to Outlet in React Router v6

about 4 years ago · Juan Pablo Isaza Report

0

state should be outside to.

<Link
  to="/forget-password"
  state={formData.email}
>

Check this for docs

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!