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

143
Views
Redirect with useNavigate and state seems to be hard to accomplish

What I am trying to do: I have a form that a client is filling out. They choose the day and time of an appointment before paying for the appointment. During payment, they get redirected to a hosted payment page and then they come back to complete the process. When its redirected, some CC info is in the path. I am trying to useParams to get that info and then redirect to the page they were on. Part of the params tells me that their payment was approved and its all I need. I need to set state to approved based on this. Then use that state in my appointment page, finish the form and submit, setting the state back to false when done.

Current code:

const location = useLocation();
  let navigate = useNavigate();
const params = new URLSearchParams(location.search);
 <Route
                path='/confirm'
                element={
                  params.has('ssl_approval_code') ? (
                  
                    navigate('./appointments', { approved: true })
                  ) : (
                    <div style={{ height: '1000px' }}>
                      Error occurred while processing card. Please use a
                      different card or contact client.
                    </div>
                  )
                }
    />
  <Route
                exact
                path='/appointments'
                element={
                  <Appointment                 
                    navigate={navigate}      
                  />
                }
    />

Then trying to just do this at the end of my submit function navigate({ approved: false });

Currently my navigate isnt working at all. Before I had version 5 of react-router-dom using Redirect, but the state was messing up. But at that time it was atleast redirecting. It just wouldnt reset state so I switched to version 6 with useNavigate.

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

0

In react-router-dom v6 the state is sent in the options object in the second argument to navigate.

useNavigate

declare function useNavigate(): NavigateFunction;

interface NavigateFunction {
  (
    to: To,
    options?: { replace?: boolean; state?: any }
  ): void;
  (delta: number): void;
}

Move the object into the state property of the options object.

navigate('./appointments', { state: { approved: false } });
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!