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

162
Views
React / React Router: trata las etiquetas <a> como etiquetas <Link>

Estoy pasando HTML precompilado a mi componente React a través de accesorios. Los datos originales se parecen a esto.

 let pageData = [ title : 'About', content: '<p>Hello <strong> World!</p><a href="/contact">Contact</a>' ]

Luego, en el componente que usa el método dangerouslySetInnerHTML SetInnerHTML porque no estoy seguro de si hay algo más que usar.

 import React from 'react'; export default class PostText extends React.Component { render() { return ( <div dangerouslySetInnerHTML={{__html: this.props.content}} /> </div> ); } }

Pero mi pregunta es, ¿cómo puedo convertir la <a href="/contact">Contact</a> a <Link to="/contact">Contact</Link> .

Incluso si no cambio la marca, ¿hay alguna manera de hacer algo como "cuando hago clic en una etiqueta <a> , el tratamiento es como etiqueta <Link> ".

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Creo que podría hacer algo como esto, interceptar enlaces, hacer clic en eventos dentro de su div y navegar con el enrutador:

 <div dangerouslySetInnerHTML={{__html: this.props.content}} onClick={event => this.navigate(event)} /> </div>

y luego:

 navigate (event) { event.preventDefault() if (event.target.tagName === 'A') { this.props.router.push(event.target.getAttribute('href')) } }
over 4 years ago · Santiago Trujillo 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!