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

160
Views
Get pathname of from where user clicked in Next.JS

I have a button in a <Nav/> component that is shared between two components. when the button is clicked it opens up a <FileUpload/> component.

<FileUpload/> can be accessed from:

<Profile /> => routes to '/profile'

<Home /> => routes to '/home'

inside <FileUpload/> is there any way to check which route the user has just come from?

so inside the <FileUpload/> component I can see:

`user has just come from ${route} route` => either /profile or /home

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

0

inside your FileUpload component import useRouter hook at the top from next/router then use it inside your component to get the pathname like this:

import { useRouter } from 'next/router'

const FileUpload = ()=> {
   const router = useRouter()
   const {pathname} = router;
  
   console.log("user come from: " + pathname)

  return (...);
}
about 4 years ago · Juan Pablo Isaza Report

0

with useRouter hook:

const router = useRouter()
console.log(router)

it gives you a lot of information check if your answer is in it;

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!