How can I fix jsx-a11y/anchor-is-valid when using the Link component in React?

前端 未结 3 1076
一整个雨季
一整个雨季 2021-02-06 22:26

In a React app

Person Link

results in the following eslint error

The href attribu

相关标签:
3条回答
  • 2021-02-06 22:49

    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" ]
        }]
      }
    }
    

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

    0 讨论(0)
  • 2021-02-06 22:53

    Perhaps you meant to put backticks instead of single-quotes in order to create a template literal. Try the following:

    <Link to={`/person/${this.state.id}/edit`}>Edit</Link>
    
    0 讨论(0)
  • 2021-02-06 23:10

    you can just write some text content inside the "a" tag and hide it with CSS (font-size:0px or something

    0 讨论(0)
提交回复
热议问题