Skip to content

Commit

Permalink
chore: use useMatch to determine current page
Browse files Browse the repository at this point in the history
  • Loading branch information
jerelmiller committed Aug 9, 2020
1 parent d00e2df commit 3b9ba0c
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/components/NavigationItems.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import cx from 'classnames';
import { BreadcrumbContext } from './BreadcrumbContext';
import styles from './NavigationItems.module.scss';
import { link } from '../types';
import { useLocation } from '@reach/router';
import { useLocation, useMatch } from '@reach/router';

const iconLibrary = {
'Collect data': 'collectData',
Expand All @@ -21,8 +21,6 @@ const iconLibrary = {
'Try our APIs': 'tryOurAPIs',
};

const normalizeUrl = (url) => url?.replace(/\/$/, '');

const getHighlightedText = (text, highlight) => {
const parts = text.split(new RegExp(`(${highlight})`, 'gi'));
return (
Expand Down Expand Up @@ -108,8 +106,7 @@ const NavItem = ({ page, depthLevel, searchTerm, filteredPageNames }) => {
}
}, [hasChangedPage, isBreadCrumb]);

const isCurrentPage =
normalizeUrl(location.pathname) === normalizeUrl(page.url);
const isCurrentPage = Boolean(useMatch(page.url || '/'));

const isToggleable = [
'Component library',
Expand Down

0 comments on commit 3b9ba0c

Please sign in to comment.