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:
parent
13f0a4f04f
commit
358e4db0e3
|
|
@ -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 (
|
||||
|
|
|
|||
Loading…
Reference in New Issue