From 56a891e6685336979a8c0c61f84ec193681472c0 Mon Sep 17 00:00:00 2001 From: hosseintaromi Date: Sat, 7 Feb 2026 13:26:10 +0330 Subject: [PATCH] fix(sidebar): improve path matching logic for sidebar menu items - Added exact matching for the wallet menu item to prevent incorrect path matches. - Enhanced the path matching logic to ensure that non-exact paths do not match partial URLs, improving navigation accuracy. These changes enhance the sidebar's routing behavior, ensuring a more intuitive user experience. --- src/components/layout/Sidebar.tsx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/components/layout/Sidebar.tsx b/src/components/layout/Sidebar.tsx index 718dbdb..cd8b21b 100644 --- a/src/components/layout/Sidebar.tsx +++ b/src/components/layout/Sidebar.tsx @@ -190,6 +190,7 @@ const menuItems: MenuItem[] = [ title: 'مدیریت کیف پول', icon: Wallet, path: '/wallet', + exact: true, }, { title: 'شارژ کیف پول', @@ -234,7 +235,14 @@ export const Sidebar = ({ isOpen, onClose }: SidebarProps) => { if (child.exact) { return currentPath === child.path; } - return currentPath.startsWith(child.path); + // For non-exact paths, check if current path starts with child path + // but also ensure it's not a partial match (e.g., /wallet should not match /wallet/credit) + if (currentPath === child.path) { + return true; + } + // Only match if current path starts with child path AND has a slash after it + // This prevents /wallet from matching /wallet/credit + return currentPath.startsWith(child.path + '/'); } return false; });