Skip to content

Next.js Link component to be styled with styled-components

License

Notifications You must be signed in to change notification settings

brunnolou/next-styled-link

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

next-styled-link

Next.js Link component to be styled with styled-components

The problem

When you style a link with styled component you loose the href="…" meaning that there is no "open in a new tap" and no SEO for indexing links.

Example:

const StyledLink = styled.a`
  color: red;
  background: blue;
`

export default () => (
  <Link prefetch href={'index'}>
    <StyledLink>My styled link</StyledLink>
  </Link>
)

In this example above Zeit Next.js Link will not pass the href to the styled-component StyledLink.

Because in the render function of source of the next/link we found this:

if (child.type === 'a' && !('href' in child.props)) {

Styled components are not child.type = a.

Usage

const Link = require('next-styled-link');

About

Next.js Link component to be styled with styled-components

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published