From 9aa1453f8073634f3506f6d42d5dbe4e6eaaa35e Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 26 Jan 2026 21:38:06 +0800 Subject: [PATCH] fix: use Link + router.refresh() for optimal navigation Based on Next.js best practices research: - Use component for prefetching and client-side navigation - Add router.refresh() onClick to force server component re-render - This preserves SPA experience while ensuring fresh data - Fixes issue where pages don't reload after URL change --- components/sidebar-history-item.tsx | 12 +++++- components/top-navbar.tsx | 67 ++++++++++------------------- 2 files changed, 34 insertions(+), 45 deletions(-) diff --git a/components/sidebar-history-item.tsx b/components/sidebar-history-item.tsx index dc9b805eb..d5f0f9ec8 100644 --- a/components/sidebar-history-item.tsx +++ b/components/sidebar-history-item.tsx @@ -1,4 +1,7 @@ +"use client"; + import Link from "next/link"; +import { useRouter } from "next/navigation"; import { memo } from "react"; import { useChatVisibility } from "@/hooks/use-chat-visibility"; import type { Chat } from "@/lib/db/schema"; @@ -37,6 +40,7 @@ const PureChatItem = ({ onDelete: (chatId: string) => void; setOpenMobile: (open: boolean) => void; }) => { + const router = useRouter(); const { visibilityType, setVisibilityType } = useChatVisibility({ chatId: chat.id, initialVisibilityType: chat.visibility, @@ -45,7 +49,13 @@ const PureChatItem = ({ return ( - setOpenMobile(false)}> + { + setOpenMobile(false); + router.refresh(); + }} + > {chat.title} diff --git a/components/top-navbar.tsx b/components/top-navbar.tsx index 2b00926ec..e9f714238 100644 --- a/components/top-navbar.tsx +++ b/components/top-navbar.tsx @@ -174,21 +174,15 @@ export function TopNavbar({ )} {/* AI智能精选 */} - + AI精选 + {/* 精选榜单 */} @@ -259,39 +253,30 @@ export function TopNavbar({ {/* 无限画布 */} - + 无限画布 + {/* 我的图册 */} - + 我的图册 + {/* 分隔线 (如果有链接或图册按钮,且是管理员) */} {isAdmin && ( @@ -300,20 +285,14 @@ export function TopNavbar({ {/* 系统设置(仅管理员可见)*/} {isAdmin && ( - + )}