React中ESLint对a标签href属性警告

React中ESLint对a标签href属性警告
强烈推介IDEA2020.2破解激活,IntelliJ IDEA 注册码,2020.2 IDEA 激活码

问题描述

在React中如果使用了a标签,但是又没有给a标签的href属性赋值有效的链接地址,则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. Learn more: https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/anchor-is-valid.md  jsx-a11y/anchor-is-valid

解决方法

在根目录下的package.json配置文件中添加如下ESLint的配置:

   // .....
  "eslintConfig": {
   
    // .....
    "rules":{
   
      "jsx-a11y/anchor-is-valid":"off"
    }
  },
  // .....
本文来源MrKorbin,由架构君转载发布,观点不代表Java架构师必看的立场,转载请标明来源出处:https://javajgs.com/archives/25228

发表评论