Skip to content

Commit

Permalink
fix: dont open links on home page
Browse files Browse the repository at this point in the history
  • Loading branch information
jerelmiller committed Aug 9, 2020
1 parent 641f057 commit de74639
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/components/NavigationItems.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,17 @@ const NavIcon = ({ page }) => {
const NavItem = ({ page, depthLevel, searchTerm, filteredPageNames }) => {
const location = useLocation();
const crumbs = useContext(BreadcrumbContext).flatMap((x) => x.displayName);
const isHomepage = location.pathname === '/';
const isBreadCrumb = crumbs.includes(page.displayName);
const matchesSearch = filteredPageNames?.includes(page.displayName);
const hasChangedPage = location.pathname !== usePrevious(location.pathname);
const shouldExpand = (isHomepage && depthLevel === 0) || isBreadCrumb;
const [toggleIsExpanded, setToggleIsExpanded] = useState(shouldExpand);
const [toggleIsExpanded, setToggleIsExpanded] = useState(isBreadCrumb);
const isExpanded = toggleIsExpanded || matchesSearch;

useEffect(() => {
if (hasChangedPage) {
setToggleIsExpanded(shouldExpand);
setToggleIsExpanded(isBreadCrumb);
}
}, [hasChangedPage, shouldExpand]);
}, [hasChangedPage, isBreadCrumb]);

const isCurrentPage =
normalizeUrl(location.pathname) === normalizeUrl(page.url);
Expand Down

0 comments on commit de74639

Please sign in to comment.