gpt4 book ai didi

reactjs - 在 React 中使用 Link 组件时如何修复 jsx-a11y/anchor-is-valid 问题?

转载 作者:行者123 更新时间:2023-12-03 12:59:51 35 4
gpt4 key购买 nike

在 React 应用程序中

<Link to={`/person/${person.id}`}>Person Link</Link>

导致以下 eslint 错误

anchor 需要 href 属性。提供有效的可导航地址作为 href 值 jsx-a11y/anchor-is-valid

链接组件产生有效的 href 属性。

<a href="#/person/2">Person Link</a>

这个错误有什么意义?我该如何解决这个问题?

任何帮助将不胜感激!

最佳答案

Link 组件生成 href 属性,因此最终 anchor 标记从可访问性的角度来看是有效的。添加an exception.eslintrc:

{
"rules": {
"jsx-a11y/anchor-is-valid": [ "error", {
"components": [ "Link" ],
"specialLink": [ "to" ]
}]
}
}

此外,GitHub 上的答案也存在同样的问题.

关于reactjs - 在 React 中使用 Link 组件时如何修复 jsx-a11y/anchor-is-valid 问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47875730/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com