allow navlink to be active at other links

This commit is contained in:
Maren Süwer
2018-09-27 09:59:25 +02:00
parent 34444ac4a9
commit a1e0e790ad

View File

@@ -7,7 +7,8 @@ import { Route, Link } from "react-router-dom";
type Props = {
to: string,
label: string,
activeOnlyWhenExact?: boolean
activeOnlyWhenExact?: boolean,
otherLocation: (route: any) => boolean
};
class NavLink extends React.Component<Props> {
@@ -16,10 +17,10 @@ class NavLink extends React.Component<Props> {
};
renderLink = (route: any) => {
const { to, label } = this.props;
const { to, label, otherLocation } = this.props;
return (
<li>
<Link className={route.match ? "is-active" : ""} to={to}>
<Link className={route.match || (otherLocation && otherLocation(route)) ? "is-active" : ""} to={to}>
{label}
</Link>
</li>