From 8cb7b592eb542fc6cab910eff7e58caae68a4580 Mon Sep 17 00:00:00 2001 From: maulanasdqn Date: Sat, 11 Apr 2026 22:23:55 +0700 Subject: [PATCH] fix: smooth client-side sidebar navigation with useNavigate Replaced tags with button + useNavigate() for instant SPA navigation without full page reloads. Sidebar now: - Uses TanStack Router useNavigate for all menu items - Closes mobile menu on navigation (onClose callback) - No more page flicker when switching between sections - Logout redirects to /auth/login via navigate Co-Authored-By: Claude Opus 4.6 (1M context) --- .../backoffice-sidebar/backoffice-sidebar.tsx | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/libs/ui/src/organisms/backoffice-sidebar/backoffice-sidebar.tsx b/libs/ui/src/organisms/backoffice-sidebar/backoffice-sidebar.tsx index 0480412..cf2d02a 100644 --- a/libs/ui/src/organisms/backoffice-sidebar/backoffice-sidebar.tsx +++ b/libs/ui/src/organisms/backoffice-sidebar/backoffice-sidebar.tsx @@ -20,7 +20,7 @@ import { } from '@ant-design/icons'; import { Button } from '../../atoms'; import { FC, ReactElement, useState } from 'react'; -import { useLocation } from '@tanstack/react-router'; +import { useLocation, useNavigate } from '@tanstack/react-router'; import { cn, For } from '@imphnen-frontend-service/utils'; import { useSession } from '@imphnen-frontend-service/service'; @@ -164,6 +164,7 @@ export const BackofficeSidebar: FC = ({ }): ReactElement => { const { signOut } = useSession(); const location = useLocation(); + const navigate = useNavigate(); const [openGroups, setOpenGroups] = useState>(() => { const initial: Record = {}; MENUS.forEach((menu) => { @@ -246,11 +247,12 @@ export const BackofficeSidebar: FC = ({ {openGroups[menu.label] && (
{menu.children.map((child) => ( - { navigate({ to: child.href as string }); onClose?.(); }} className={cn( - 'flex items-center gap-3 px-2 py-2.5 rounded-md', + 'flex items-center gap-3 px-2 py-2.5 rounded-md cursor-pointer text-left w-full', isActive(child.href) ? 'bg-primary-100 text-primary-700 hover:bg-primary-200' : 'text-gray-700 hover:bg-gray-100' @@ -260,17 +262,18 @@ export const BackofficeSidebar: FC = ({ {child.label} - + ))}
)} ) : ( - { if (menu.href) { navigate({ to: menu.href as string }); onClose?.(); } }} className={cn( - 'flex items-center justify-items-start gap-3 px-2 py-2.5', + 'flex items-center justify-items-start gap-3 px-2 py-2.5 cursor-pointer text-left w-full', menu.href && isActive(menu.href) ? 'bg-primary-500 text-white rounded-md' : 'text-gray-700 hover:bg-gray-100' @@ -278,7 +281,7 @@ export const BackofficeSidebar: FC = ({ > {menu.icon} {menu.label} - + ) } @@ -288,7 +291,7 @@ export const BackofficeSidebar: FC = ({