Not too familiar with react router, but I need the functionality of the NavLink to set the active class on the parent li
element, and not the a
ele
I am just starting with the react, so not sure if this is the best practices, but after going through router v4 docs, I used withRouter props -> location.pathname and compared it to my route.
Here is the Navigation.js:
import React from 'react';
import { withRouter } from 'react-router-dom';
import NavLink from '../General/NavLink';
const activeClass = (path, link) => {
if (path === link) {
return true;
}
return false;
};
const Navigation = props => {
const { location } = props;
return (
Dashboard
Users
Projects
Google
);
};
export default withRouter(Navigation);
From there you have parent and child classes that you can use on child component.