在React中使用Link组件时如何修复jsx-a11y/anchor-is-valid? [英] How can I fix jsx-a11y/anchor-is-valid when using the Link component in React?

查看:96
本文介绍了在React中使用Link组件时如何修复jsx-a11y/anchor-is-valid?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在React应用中

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

导致以下eslint错误

results in the following eslint error

在锚点上必须具有href属性.提供有效的可导航地址作为href值jsx-a11y/anchor-is-valid

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

The Link component results in a valid href attribute.

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

此错误的含义是什么?我该如何解决?

What is the point of this error? How do I fix this?

任何帮助将不胜感激!

推荐答案

Link 组件会生成 href 属性,因此从锚点的可访问性角度来看,最后的定位标记是有效的看法.添加 .eslintrc 的一个例外:

The Link component generates href attribute so in the end anchor tag is valid from the accessibility point of view. Add an exception to .eslintrc:

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

此外,在 GitHub 上也有相同的问题a>.

Additionally, there is the same issue with a answer on GitHub.

这篇关于在React中使用Link组件时如何修复jsx-a11y/anchor-is-valid?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆