React项目中ESLint对a标签无href属性的警告问题

当我们react项目中使用a标签但是没加href属性时,会看到如下警告:

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. Learn more: https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/HEAD/docs/rules/anchor-is-valid.md jsx-a11y/anchor-is-valid

我们可以在package.json文件中添加配置消除这个警告

 "eslintConfig": {
    ..."rules": {
      "jsx-a11y/anchor-is-valid": "off"
    }
  }

 

posted @ 2022-12-09 16:49  抽风的皮鞭  阅读(552)  评论(0编辑  收藏  举报