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

Eric the Red :

In a React app

<Link to={`/person/${person.id}`}>Person Link</Link>

results in the following eslint error

The href attribute is required on an anchor. Provide a valid, navigable address as the href value jsx-a11y/anchor-is-valid

The Link component results in a valid href attribute.

<a href="#/person/2">Person Link</a>

What is the point of this error? How do I fix this?

Any help would be greatly appreciated!

Tomasz Mularczyk :

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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

how can i use if inline react jsx

How can I spread props to a React component that uses exact props when using Flow?

How can I disable a link in the vue component?

How, using react-router-dom, can I direct a link to render a general post component, populated with props?

React JSX How can I switch component state between two objects on a timer

How to render a component using innerHTML in React jsx

How can I test an onClick line of a React component using Jest?

How can I pass props from one component to another using Link and router in react

Moment.JS saying date is invalid when using .format() but is valid when using isvalid() function how can i fix this?

How can I Dynamically switch a component into another page using <Link to=

React: How do I fix getting undefined when passing api data to child component using axios?

How can I replace bits or string with React component, react-router-dom Link or an anchor tag <a></a>

How can I fix this ReferenceError when using .setSelfDeaf()?

How can I return a react component using withStyles?

How can I avoid using default export when exporting a component in React?

How can I append an item to an array in a React component using hooks?

How to write the default translation with react-i18next Trans component, that is valid JSX when using interpolated variables?

How can I sort element in jsx in react?

How can I pass function using props in React Router Link?

How can I avoid an infinite recursion loop when calling an API endpoint using axios to update a component in React

How can I mount component by using react hooks?

How can I fix a macro not being defined when I link a source file?

React - How can I render a component within a class by using OnClick?

I can not get the state from react router Link component using useLocation. So how can I pass it?

How can I close my hamburger menu when clicking on a link using React JS? (using ReactJS hooks)

How to control JSX component using filter() in React?

How can I link to the corresponding child React component?

How can I fix 'Cannot read properties of undefined' error when accessing prop values in a child component in React?

How can I fix the alignment of the closing tag when using XSLT?