1,环境介绍:
通过create-react-app
搭建React
项目,添加路由组件React-Router
,样式组件Antd Design
(简称antd
),状态管理机react-redux
等组件。
2,问题出现:
我在index.js
中添加<a>点击进入首页</a>
,保存后npm start
运行项目,出现问题。
3,警告描述:
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
4,问题解决:
第一步:将现有代码保存到本地git:
git add .
git commit -m "init"
第二步:执行以下命令:
npm run eject
- 注意:如果是刚创建的新项目,安装脚手架完成后首先执行
npm run eject
。
5,添加配置:
在package.json文件中添加如下代码:
"eslintConfig": {
"extends": "react-app",
"rules":{
"jsx-a11y/anchor-is-valid":"off"
}
}