Skip to content

Instantly share code, notes, and snippets.

@codewithleader
Last active January 4, 2023 16:45
Show Gist options
  • Save codewithleader/1d343f4ceccda3dd10420ce0aba10f48 to your computer and use it in GitHub Desktop.
Save codewithleader/1d343f4ceccda3dd10420ce0aba10f48 to your computer and use it in GitHub Desktop.
NextJS v13: Nota de Actualizacion sobre NextLink, agregar legacyBehavior

Next13 - Nueva sintaxis con MaterialUI

Hay dos posibles soluciones a un inconveniente que introdujo Next13 con los nuevos links.

Antes:

<NextLink href='/category/men' passHref>
  <Link>
    <Button color={ asPath === '/category/men' ? 'primary':'info'}>Hombres</Button>
  </Link>
</NextLink>
  • Posible solución 1: agregar legacyBehavior, el cual deja todo como estaba en Next12 y mantiene la compatibilidad
<NextLink href='/category/men' passHref legacyBehavior>
  <Link>
     <Button color={ asPath === '/category/men' ? 'primary':'info'}>Hombres</Button>
  </Link>
</NextLink>
  • Posible solución 2: Evitar que se genere un nuevo <a> (Anchor tag) cuando usamos el Material UI Link
<NextLink
   href={ router.query.p ? `/auth/register?p=${ router.query.p }`: '/auth/register' }
>
    <Link underline='always' component={'span'}>
        ¿No tienes cuenta?
    </Link>
</NextLink>

Referencias:

https://nextjs.org/docs/api-reference/next/link

https://nextjs.org/blog/next-13#nextlink

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment