I want to include a very basic Navbar on my site using React Router but either the styles or routes get messed up depending on what I change.
Here it says to use Navbar, Nav, and Nav.Link https://react-bootstrap.github.io/components/navs/#nav-link-props so I want to use these.
The problem is, it seems to me that the Nav.Link needs the href attribute to send the user to that route, for example /One. But then the One link at the top doesn't get active styles. If I remove the href attribute, it gets the active styles when I click on that link, but doesn't send the user to /One or load the component I want for that route obviously.
I don't see a SO answer about this that uses these tags, just answers using Link and NavLink which the URL I linked doesn't use. There isn't an example on that page either that uses multiple href attributes. What am I missing? Below is my code.
class Header extends Component {
render() {
return (
<Navbar bg="light" variant="light" fixed="top">
<Navbar.Brand href="#">MySite</Navbar.Brand>
<Nav>
<Nav.Link href="/" activeClassName="active" eventKey="/">Home</Nav.Link>
<Nav.Link href="/one" activeClassName="active" eventKey="/one">One</Nav.Link>
<Nav.Link href="/two" activeClassName="active" eventKey="/two">Two</Nav.Link>
</Nav>
</Navbar>
)
}
}
class App extends Component {
render() {
return (
<Router>
<div className="App">
<Route path="/" exact strict component={Redcircle} />
<Route path="/one" exact strict component={Bluesquare} />
<Route path="/two" exact strict component={Greentriangle} />
</div>
</Router>
);
}
}
Expected result: Navbar that changes url to /one, loads component Bluesquare, and makes the word One in the Navbar have active styles Actual result: Either route loads or One has active styles