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

317
Views
¿Cómo puedo obtener la URL anterior en javascript?

Necesito obtener la URL anterior en un proyecto nextjs. Encontré esto pero no ayuda porque siempre me imprime la URL base ( http://localhost:3000/ ) con este método ( document.referrer ). También traté de insertar un estado en window.history basado en el documento oficial del desarrollador mozilla .

En el último caso, hago clic en un enlace y me redirige a otra página. En esta página necesito saber de dónde vengo. Lo intenté:

 //pathname is a string containing the actual pathname history.pushState({prevPath: pathname},pathname)

Si imprimo el historial en la nueva página, no veo ningún estado previo en el campo de estado.

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

0

Simplemente puede crear un estado que es un objeto que tiene dos propiedades: URL previousUrl y currentUrl de esta manera:

 const urlReducer = (state={previousUrl: null, currentURL: null},action) => { switch(action.type){ case "SET_URLS": return {previousUrl: state.currentUrl, currentUrl: window.location.href} default: return state; } }

Entonces todo lo que necesita hacer es enviar una acción en cada página que visite como esta:

 const dispatch = useDispatch(); useEffect(()=>{ dispatch({type: "SET_URLS"}); },[]);
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!