UNPKG

@darwino/darwino-react-bootstrap

Version:

A set of Javascript classes and utilities

46 lines (40 loc) 1.41 kB
/* * (c) Copyright Darwino Inc. 2014-2017. */ import React, {Component} from "react"; import PropTypes from 'prop-types'; import { Route, Link } from "react-router-dom"; class NavLink extends Component { static contextTypes = { router: PropTypes.object } constructor(props) { super(props); this.onClick = this.onClick.bind(this) } onClick() { // The onSelect prop is passed by the react-bootstrap component // We have to honor them in order to collapseOnSelect if(this.props.onSelect) { this.props.onSelect(); } } render() { // remove some properties to avoid // Warning: Unknown props `active`, `activeKey`, `activeHref` on <a> tag. Remove these props from the element. For details, see https://fb.me/react-unknown-prop // in a (created by Link) // in Link (created by Route) // // onSelect is passed by react const { router } = this.context; const { to, children, exact, active, activeKey, activeHref, ...props } = this.props; return ( <Route path={to} exact={exact} children={({match}) => ( <li className={match ? 'active' : ''}> <Link to={to} {...props} onClick={this.onClick}>{children}</Link> </li> )}/> ) } } export default NavLink