fix(docs): sidebar active state not showing due to trailing slash mismatch

Next.js usePathname() returns paths with trailing slashes during static
generation (e.g., /docs/) but navigation hrefs use paths without trailing
slashes (e.g., /docs). The strict equality comparison was always failing.

Added path normalization to strip trailing slashes before comparison.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Oleg Proskurin 2025-12-31 16:03:46 +07:00
parent 13f0a4f04f
commit 358e4db0e3
1 changed files with 5 additions and 1 deletions

View File

@ -80,7 +80,11 @@ export const DocsSidebar = ({ currentPath }: DocsSidebarProps) => {
);
};
const isActive = (href: string) => currentPath === href;
// Normalize path by removing trailing slash (except for root)
const normalizePath = (path: string) => (path.length > 1 && path.endsWith('/') ? path.slice(0, -1) : path);
const normalizedCurrentPath = normalizePath(currentPath);
const isActive = (href: string) => normalizedCurrentPath === href;
const isExpanded = (label: string) => expandedSections.includes(label);
return (