我该如何在NextJS中在新标签页中打开链接?我尝试过这个:
<Link href="https://twitter.com/" passHref>
<a target="_blank">
<div className={`${dark ? styles.iconTwitterWhite : styles.iconTwitter} mr-3`} />
</a>
</Link>
它会在新选项卡中打开链接,但我收到了一个ESLint
的提示消息:
它会在新选项卡中打开链接,但我收到了一个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.
还有其他方法可以做吗?
rel="noopener noreferrer"
以防止新打开的标签页恶意修改原始标签页。关于linting问题,这是Next.js<Link>
组件的已知限制。请参见此处可能的解决方案:https://github.com/vercel/next.js/issues/5533 - juliomalves