NextJS でリンクを新しいタブで開くにはどうすればいいですか? 質問する

NextJS でリンクを新しいタブで開くにはどうすればいいですか? 質問する

NextJS で新しいタブでリンクを開くにはどうすればよいですか? これを試しました:

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

リンクは新しいタブで開きますが、次のようなESLintメッセージが表示されます:

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.

他に方法はありますか?

ベストアンサー1

これは外部リンクなので、リンクを使用する必要はありません。

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

おすすめ記事