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

327
Views
Next.js: how to go to parent page from current child page?

my apology if this is a super dumb question, I'm a beginner of Next.js and React.js.

I have some basic knowledge that in Next.js, we can create a hierarchy of pages, and the path of a xx_page.js file would be the url route for that js file, as described in the documentation.

For example, my pages are structured as follows,

pages  // a folder
| -- home  // a folder
|     | -- index.js  // a file, the code for route "/home"
      | -- sports  // a folder
      |     | -- index.js  // a file, the code for route "/home/sports"
      |     | -- football.js  // a file, the code for "/home/sports/football"

Suppose the current page is at route "xxx.com/home/sports/football", and on the page there is a "Back" button, after clicking it, we should go back to "xxx.com/home/sports".

I failed to figure out a proper way to do that, mostly what I found by Google are about going back to the previous page, and not what I want.

Please give me some help about how to do it in Next.js, thanks!

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

0

There's no correct definition of "Back", so you have to define it. For your button, if you do the following

      <Link href="/home/sports">
        <a className="back">←</a>
      </Link>

It should behave exactly what you wanted.

about 4 years ago · Juan Pablo Isaza Report

0

if you are looking to remove the last part of the URL, you can do the below

let a = window.location.href.split("/")
a.pop();
window.location.href = a.join("/");
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!