如何在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.
还有另一种方法吗?
回答
由于这是一个外部链接,您不需要使用 Link
<a target="_blank" href="https://twitter.com/" rel="noopener noreferrer">
<div className={`${dark ? styles.iconTwitterWhite : styles.iconTwitter} mr-3`} />
</a>