React – The href attribute requires a valid value to be accessible

React

React lets you build user interfaces out of individual pieces called components. Create your own React components like Thumbnail, LikeButton, and Video. Then combine them into entire screens, pages, and apps.

How to reproduce it

export class ComponentClass extends Component {

    render() {
        return (
            <>
                <h1>Class component</h1>
                <a href='#'>Link</a>
            </>
        );
    }
}

Error

The href attribute requires a valid value to be accessible. Provide a valid, navigable address as the href value. If you cannot provide a valid href, but still need the element to resemble a link, use a button and change it with appropriate styles.

Solution

Use /# instead of #.


import { Component } from 'react';

export class ComponentClass extends Component {

    render() {
        return (
            <>
                <h1>Class component</h1>
                <a href='/#'>Link</a>
            </>
        );
    }
}
https://www.mldgroup.com

Vyštudovaný top manažér pôsobiaci najmä ako manažér, marketér, softvérový inžinier, konzultant, bloger, YouTuber a zatiaľ neúspešný hudobník a producent. V rámci praxe pôsobil v rôznych odvetviach na rôznych pozíciách v malých aj veľkých firmách, vrátane spoluprác a partnerstiev s významnými firmami či poradenskými spoločnosťami.

Pridaj komentár

Vaša e-mailová adresa nebude zverejnená. Vyžadované polia sú označené *