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

136
Views
How Could I redirect login page using Javascript
const RequireAuth = ({ children }) => {
    const [user, loading, error] = useAuthState(auth);

    const location = useLocation();
    if (loading) {
        return <Loading></Loading>
    }
    if (!user) {
        return <Navigate to="/login" state={{ from: location }} replace />;
    }
    return children;
};

export default RequireAuth;
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You can also do something like this:

if (!user) {
   window.location.href = `http://localhost:3000/login?from=${location}` // for example
}

and then parse query string to get a value of location


UPDATE:

Doing "routing" as I mentioned above is wrong and it will lead to hard to debug bugs. Use useNavigate hook from react-router-dom instead: https://reactrouter.com/docs/en/v6/hooks/use-navigate

about 4 years ago · Juan Pablo Isaza Report

0

const [user, loading] = use Auth State(auth)
const location = use Location()

if (loading) {
    return <Loading></Loading>
}
if (!user) {
    return <Navigate to="/login" state={{ from: location }} replace ></Navigate>
}
return children

};

export default Private Route;

(sorry for space)

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!