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

267
Views
Redirect History.back() to another path with JavaScript

Expected When the user is on the /animals route, when they click the back button on the browser i want to redirect them back to another route instead of the previous route.

What's actually happening:

I am trying to redirect the url when the user clicks the back button on the browser, however i am having trouble with this where it is replacing the current location when the page loads on that route instead of replacing it when the user clicks the back button and it removes the pathname on top of that.

    if (window.location.hash === '#/animals') {
        return history.pushState({}, '', '/home');
    }
about 4 years ago · Santiago Gelvez
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!