Search code examples
next.js

How to open a link in a new Tab in NextJS?


How can i open a link in a new Tab in NextJS ? i tried this :

      <Link href="https://twitter.com/" passHref>
        <a target="_blank">
          <div className={`${dark ? styles.iconTwitterWhite : styles.iconTwitter} mr-3`} />
        </a>
      </Link>

It opens the link in a new Tab but i have an ESLint message saying :

ESLint: The href attribute is required for an anchor to be keyboard accessible. Provide a valid, navigable address as the href value. If you cannot provide an href, but still need the element to resemble a link, use a button and change it with appropriate styles.

Is there another way to do it ?


Solution

  • As this is an external link, you don't need to use Link

    <a target="_blank" href="https://twitter.com/" rel="noopener noreferrer">
        <div className={`${dark ? styles.iconTwitterWhite : styles.iconTwitter} mr-3`} />
     </a>