0

I am starting with react and I would like to make simple navigation bar for beginning. I am using component for item in the list of links. Which is used in the component with whole list and than it´s rendered by another component.

This is one item in the list.

import React from 'react';
import ReactDOM from 'react-dom';

export default class NavLi extends React.Component {

render() {
    return (
        <li className="nav-item active"><a className="nav-link" href={this.props.href}>{this.props.children}</a></li>
    );
}
}

Called by this class:

import React from 'react';
import ReactDOM from 'react-dom';
import NavLi from './NavLi';

export default class NavUl extends React.Component {

render() {
    return (
        <ul className="nav navbar-nav">
            <NavLi href="home">Home</NavLi>
            <NavLi href="about">About</NavLi>
            <NavLi href="contact">Contact</NavLi>
        </ul>
    );
}
}

And again and again.

import Log from './Log';
import NavUl from './NavUl';

export default class Nav extends React.Component {

render() {
    return (
        <nav className="navbar navbar-fixed-top navbar-dark bg-inverse">
            <div className="container">
                <a className="navbar-brand" href="#">ProjectName</a>
                <NavUl/>
                <Log/>
            </div>
        </nav>

    );
}
}

.

import React from 'react';
import ReactDOM from 'react-dom';
import Nav from './navbar/Nav';

class App extends React.Component {
  render() {
    return (
        <div>
            <Nav/>
        </div>
    );
}
}

ReactDOM.render(<App />, document.getElementById('react'));

This whole thing is in .html like this: <div id="react"></div>

I am using bootsrtap4 and the problem is, that in every item in the list of navigation bar I can´t see css class at <a></a> when I run the app. Everything worsk fine, but in tags <a></a> are no classess at all after running this app screenshot from browser.

Any advice why this is not working? Thank you.

4
  • Your 2 classes have name NavLi Commented Jan 5, 2017 at 9:16
  • I haven´t noticed, thank you, but it did not solve my problem. Commented Jan 5, 2017 at 9:31
  • Yes, that's why i've added it as comment, not answer :) Commented Jan 5, 2017 at 9:36
  • Your code actually works. Check the fiddle Commented Jan 5, 2017 at 10:04

2 Answers 2

3

From the spec:

Content model: Transparent, but there must be no interactive content or a element descendants.

Nested <a> elements are forbidden in HTML. You are bouncing off error recovery in the browser.

Sign up to request clarification or add additional context in comments.

3 Comments

I think I know what you mean, I tried to move <a></a> outside of the <li>, but it did not solve the problem. Weird thing is, that if I have it like this in clean .html, it works fine.
In that case, checkout your dev tools to see what html output you'll get. It might be somewhat different then you expect
There is a screenshot at the end of the question. The class attribute just disappears from <a> element.
0

I think you didn't define the style in CSS file. Can you find a style of 'nav-link' in CSS file? In my case, the class did not appear when I don't define the style in CSS file.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.