• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Evaluaciones
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

137
Vistas
Refresh component on route only in React-Router V5

Is there a way to refresh a route when using react router v5. I have a onClick function which navigates to a route and refetches the data, however that is only if I use history.push('/') I want to refresh the component even if I am just on the same route '/' for example I am currently doing:

is there a better way to navigate programatically in react-router?

currently this handleChange method is in the header component.

const handleChange = (event: any) => {
    setValue(event.target.value);
    if (history.location.pathname === "/") {
        alert('Changing');
        // need to refresh component here?
    }
    history.push('/');
};

routing is:

 <QueryClientProvider client={queryClient}>
        <BrowserRouter>
          <Header links={items} locations={Locations} />
          <div className="App">
            <Switch>
              <Route exact path="/" component={home} />
              <Route path="/details/:id" render={(props: RouteComponentProps<any>) => <Detail {...props} />} />
              <Route component={NotFound} />
            </Switch>
          </div>
        </BrowserRouter>
        <ReactQueryDevtools />
      </QueryClientProvider>
about 3 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda