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

642
Views
Is there an equivalent for {useLocation} from 'react-router-dom' in nextjs

import { useLocation } from 'react-router-dom';

I'm currently using Nextjs, I need help for an equivalent of useLocation

`

 import Link from 'next/link';
 import { FC } from 'react';
 import {useRouter} from 'next/router';
 import { useStore } from '../store';`



const PrivateRoute: FC = ({ children }) => {
const currentUser = useStore((state) => state.currentUser);
const location = useRouter();`

if (!currentUser)
    return (
        <Link
            href={`/sign-in?redirect=${encodeURIComponent(
                location.pathname + location.push('chat')
            )}`}
        />
    );
return <>{ children }</>

}

export default PrivateRoute;`

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

0

You can use useRouter from 'next/router' and then you can either use pathname or asPath and then you conditionally add slug or params. Rest you can find more information via documentation posted by others.

about 4 years ago · Juan Pablo Isaza Report

0

Yea you can use useNavigate in react-router-dom v6 and you can use useHistory in react-router-dom < v6

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!