I use a Navbar as a component on page, which uses Router to change the content. Everything is working fine, so far. But I can´t figure out, how I can set the state of the links in the Navbar to active, when they are clicked. I think, I have to bind the activeKey of the Nav element to the location.pathname of the active content.
This is my Navbar component:
import React from 'react';
import { Navbar, Nav } from 'react-bootstrap';
class Navbar extends React.Component{
constructor() {
super();
this.state = {
show: false
};
}
render(){
return(
<div>
<Navbar collapseOnSelect expand="lg" bg="dark" variant="dark">
<Navbar.Brand >Filmmusic</Navbar.Brand>
<Navbar.Toggle aria-controls="responsive-navbar-nav" />
<Navbar.Collapse id="responsive-navbar-nav">
<Nav activeKey="/" className="mr-auto">
<Nav.Link href="/">Home</Nav.Link>
<Nav.Link href="/about">About</Nav.Link>
<Nav.Link onClick = {()=>{this.handleModal()}}>Contact</Nav.Link>
</Nav>
<Nav>
<Nav.Link href="/impressum">Impressum</Nav.Link>
<Nav.Link href="/datenschutzerklaerung">Datenschutzerklärung</Nav.Link>
</Nav>
</Navbar.Collapse>
</Navbar>
</div>
)
}
}
export default Navbar;