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.
This commit is contained in:
parent
fce23a41e2
commit
56a891e668
|
|
@ -190,6 +190,7 @@ const menuItems: MenuItem[] = [
|
||||||
title: 'مدیریت کیف پول',
|
title: 'مدیریت کیف پول',
|
||||||
icon: Wallet,
|
icon: Wallet,
|
||||||
path: '/wallet',
|
path: '/wallet',
|
||||||
|
exact: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'شارژ کیف پول',
|
title: 'شارژ کیف پول',
|
||||||
|
|
@ -234,7 +235,14 @@ export const Sidebar = ({ isOpen, onClose }: SidebarProps) => {
|
||||||
if (child.exact) {
|
if (child.exact) {
|
||||||
return currentPath === child.path;
|
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;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue