Skip to content

Conversation

@MohsenBg
Copy link

…agement in NavigationItem.jsx

Refactor path handling in useEffect for improved navigation state management

  • Replaced complex URL parsing logic with simpler pathname checks.
  • Converted from checking window.location.href and window.location.origin to using window.location.pathname for cleaner path management.
  • Added handling for special paths like '/admin/products/new', '/admin/coupon/new', and '/admin' to set active state based on exact path matches.
  • Enhanced logic to ensure correct navigation item activation based on current path, handling cases where new items should be activated rather than general categories.

Changes:

  • Simplified path comparison and activation logic.
  • Addressed specific cases for 'new' items to ensure correct active state management.

PR Checklist

Please check if your PR fulfills the following requirements:

  • Tests for the changes have been added (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe:

What is the current behavior?

When I click 'New Product', the navigation item does not become active (The 'Product' item is active instead of 'New Product'.). However, when I click 'New Coupon', the navigation item becomes active as expected.

product

Screenshot_20240912_220908

coupon

Screenshot_20240912_221411

Issue Number: N/A

What is the new behavior?

I fixed the issue, and now 'Product' behaves the same way as 'New Coupon'—the navigation item becomes active as expected.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

…agement in NavigationItem.jsx

## Refactor path handling in useEffect for improved navigation state management

- Replaced complex URL parsing logic with simpler pathname checks.
- Converted from checking `window.location.href` and `window.location.origin` to using `window.location.pathname` for cleaner path management.
- Added handling for special paths like '/admin/products/new', '/admin/coupon/new', and '/admin' to set active state based on exact path matches.
- Enhanced logic to ensure correct navigation item activation based on current path, handling cases where new items should be activated rather than general categories.

Changes:
- Simplified path comparison and activation logic.
- Addressed specific cases for 'new' items to ensure correct active state management.
@treoden treoden closed this Oct 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants