首页 > 其他分享 >React项目中ESLint对a标签无href属性的警告问题

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

时间:2022-12-09 17:02:53浏览次数:46  
标签:valid a11y React href ESLint 警告 jsx anchor

当我们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"
    }
  }

 

标签:valid,a11y,React,href,ESLint,警告,jsx,anchor
From: https://www.cnblogs.com/maxiaocang/p/16969392.html

相关文章