Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

143
Vistas
Button Click inside anchor tag not working in React Js Component

Button onClick not executing the triggerThis function because it is wrapped with react-router-dom Link component

Expected behaviour: Card click should navigate to /app/url and on button click the url navigation should be prevented and should run triggerThis function.

I want onClick button prevent navigation. but when i click outside button the navigation should work .. triggerThis is a function that just console.log("hello")

<Card>
    <Link to={`/app/url`}>
       <h1>Title</h1>
       <p>Paragraph</p>
       <button onClick={triggerThis}></button>
    </Link>
   
 </Card>
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You really shouldn't place interactive elements within other interactive elements, but if you want to allow the button to be independently clickable and not trigger the navigation of the wrapping Link component then you should stop the click event propagation. This prevents the click event from propagating further up the DOMtree to the Link element, thus preventing the navigation action from occurring.

Example:

const clickHandler = e => {
  e.stopPropagation();
  ...
};

...

<Card>
  <Link to="/app/url">
    <h1>Title</h1>
    <p>Paragraph</p>
    <button onClick={clickHandler}>
      ...
    </button>
  </Link>
</Card>
about 4 years ago · Juan Pablo Isaza Denunciar
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 Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda