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

302
Views
El enrutador next.js cambia la URL, pero sigue mostrando la misma página. y no navega a otra página

Tengo una ruta /discovery donde muestro los resultados de mi búsqueda, también intento sincronizar mi estado de búsqueda con los parámetros de consulta de URL, por lo que si el usuario escribe "pollo", la URL se convierte en - /discovery?query=chicken&page=1

una vez que el usuario haga clic en el resultado, navegará a /mealpreview/[id]

Sin embargo, cuando intento navegar hacia atrás de esta manera:

 <IconButton color="inherit" onClick={() => router.back()}> <ArrowBackIcon /> </IconButton>

la URL vuelve a cambiar a - /discovery?query=chicken&page=1 pero sigue mostrando la misma página.

Cuando vuelvo a hacer clic en el botón Atrás, funciona y vuelve a /discovery

Cuando no uso parámetros de URL, todo funciona, ¿qué sucede aquí?

Por cierto, así es como sincronizo el estado de mi URL:

 import React, { Component } from "react"; import qs from "qs"; const updateAfter = 700; export const isClient = !(typeof window === "undefined"); const searchStateToURL = (searchState) => searchState ? `${window.location.pathname}?${qs.stringify(searchState)}` : ""; const withURLSync = (TestSearch) => class WithURLSync extends Component { state = { searchState: qs.parse(isClient && window.location.search.slice(1)), }; componentDidMount() { if (isClient) { window.addEventListener("popstate", this.onPopState); } } componentWillUnmount() { clearTimeout(this.debouncedSetState); window.removeEventListener("popstate", this.onPopState); } onPopState = ({ state }) => this.setState({ searchState: state || {}, }); onSearchStateChange = (searchState) => { clearTimeout(this.debouncedSetState); this.debouncedSetState = setTimeout(() => { window.history.pushState( searchState, null, searchStateToURL(searchState) ); }, updateAfter); this.setState({ searchState }); }; render() { const { searchState } = this.state; return ( <TestSearch {...this.props} searchState={searchState} onSearchStateChange={this.onSearchStateChange} createURL={searchStateToURL} /> ); } }; export default withURLSync;
about 4 years ago · Santiago Trujillo
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!