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

55
Views
Gatsby Link no funciona con isPartially Active en páginas renderizadas MDX

He estado construyendo un sitio estático con gatsby y algunas secciones he renderizado páginas escritas como MDX y analizadas a través de sus propios diseños. Todo esto es a través del archivo gatsby-plugin-mdx y funciona muy bien.

Sin embargo, estoy tratando de hacer que la navegación de nivel superior se destaque como activa cuando un usuario navega a una subpágina en esa sección. Estoy usando el código de los documentos de Gatsby y funciona en las páginas que creé como archivos JS normales.

Ejemplo:

 <Link partiallyActive={true} activeClassName="header-nav-active" to={menu.url} title={menu.title}> {menu.label} </Link>

Parece que no parece funcionar para las páginas MDX, aunque lo que se representa en location.pathname es lo mismo. Mi estructura actual es:

 src -pages --section ----section-subpage.js --other section ----other-section-sub -----index.mdx ----other-section-sub-2 -----index.mdx

En última instancia, si observa este diseño, me gustaría que "Figma" se resalte como activo cuando navegue por las subpáginas de esa sección.

ingrese la descripción de la imagen aquí

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

0

¿Has intentado usar la función de ayuda getProps ? Debido a que el enrutador de Gatsby se extiende desde el de React ( @reach/router ), puede aprovechar los props avanzados para personalizar su estilo

Puede crear un enlace partiallyActive activo como:

 const isPartiallyActive = ({ isPartiallyCurrent }) => { return isPartiallyCurrent ? { className: 'navlink-active navlink' } : { className: 'navlink' } } const PartialNavLink = props => ( <Link getProps={isPartiallyActive} {...props}> {props.children} </Link> )

Y luego simplemente use:

 <PartialNavLink to="/figma">Figma</PartialNavLink>

O de una manera no refinada:

 <Link getProps={({ isPartiallyCurrent }) => isPartiallyCurrent ? { className: "active" } : null } to={"/figma"}> Figma </Link>
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!