• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

603
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 3 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 3 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 3 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 Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error