Merge branch 'sidebar-nav-fix' into 'main'

SidebarNavigationLink: fix isActive

See merge request soapbox-pub/soapbox!3192
This commit is contained in:
Alex Gleason 2024-10-26 22:44:17 +00:00
commit c9678b846e
1 changed files with 4 additions and 2 deletions

View File

@ -1,6 +1,6 @@
import clsx from 'clsx'; import clsx from 'clsx';
import React from 'react'; import React from 'react';
import { NavLink } from 'react-router-dom'; import { NavLink, useLocation } from 'react-router-dom';
import { Icon, Text } from './ui'; import { Icon, Text } from './ui';
@ -24,7 +24,9 @@ interface ISidebarNavigationLink {
/** Desktop sidebar navigation link. */ /** Desktop sidebar navigation link. */
const SidebarNavigationLink = React.forwardRef((props: ISidebarNavigationLink, ref: React.ForwardedRef<HTMLAnchorElement>): JSX.Element => { const SidebarNavigationLink = React.forwardRef((props: ISidebarNavigationLink, ref: React.ForwardedRef<HTMLAnchorElement>): JSX.Element => {
const { icon, activeIcon, text, to = '', count, countMax, onClick } = props; const { icon, activeIcon, text, to = '', count, countMax, onClick } = props;
const isActive = location.pathname === to; const { pathname } = useLocation();
const isActive = pathname === to;
const handleClick: React.EventHandler<React.MouseEvent> = (e) => { const handleClick: React.EventHandler<React.MouseEvent> = (e) => {
if (onClick) { if (onClick) {