fix: force full page navigation with window.location.href
- Use window.location.href for guaranteed navigation - Prevent default and manually navigate to avoid App Router cache issues - This ensures single-click navigation works reliably
This commit is contained in:
parent
9aa1453f80
commit
50c3d7a182
@ -1,7 +1,5 @@
|
||||
"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";
|
||||
@ -40,24 +38,26 @@ const PureChatItem = ({
|
||||
onDelete: (chatId: string) => void;
|
||||
setOpenMobile: (open: boolean) => void;
|
||||
}) => {
|
||||
const router = useRouter();
|
||||
const { visibilityType, setVisibilityType } = useChatVisibility({
|
||||
chatId: chat.id,
|
||||
initialVisibilityType: chat.visibility,
|
||||
});
|
||||
|
||||
const handleNavigation = (e: React.MouseEvent) => {
|
||||
e.preventDefault();
|
||||
setOpenMobile(false);
|
||||
window.location.href = `/chat/${chat.id}`;
|
||||
};
|
||||
|
||||
return (
|
||||
<SidebarMenuItem>
|
||||
<SidebarMenuButton asChild isActive={isActive}>
|
||||
<Link
|
||||
href={`/chat/${chat.id}`}
|
||||
onClick={() => {
|
||||
setOpenMobile(false);
|
||||
router.refresh();
|
||||
}}
|
||||
<a
|
||||
href={`/chat/${chat.id}`}
|
||||
onClick={handleNavigation}
|
||||
>
|
||||
<span>{chat.title}</span>
|
||||
</Link>
|
||||
</a>
|
||||
</SidebarMenuButton>
|
||||
|
||||
<DropdownMenu modal={true}>
|
||||
|
||||
@ -174,15 +174,18 @@ export function TopNavbar({
|
||||
)}
|
||||
|
||||
{/* AI智能精选 */}
|
||||
<Link
|
||||
<a
|
||||
href="/featured"
|
||||
className="flex items-center gap-1 h-8 px-3 text-white hover:bg-white/15 hover:text-white rounded-full transition-colors text-sm font-medium"
|
||||
title="AI智能精选"
|
||||
onClick={() => router.refresh()}
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
window.location.href = "/featured";
|
||||
}}
|
||||
>
|
||||
<Sparkles className="h-4 w-4 text-yellow-400" />
|
||||
<span>AI精选</span>
|
||||
</Link>
|
||||
</a>
|
||||
|
||||
{/* 精选榜单 */}
|
||||
<DropdownMenu open={rankingOpen} onOpenChange={setRankingOpen}>
|
||||
@ -268,15 +271,18 @@ export function TopNavbar({
|
||||
</button>
|
||||
|
||||
{/* 我的图册 */}
|
||||
<Link
|
||||
<a
|
||||
href="/gallery"
|
||||
className="flex items-center gap-1 h-8 px-3 text-white hover:bg-white/15 hover:text-white rounded-full transition-colors text-sm font-medium"
|
||||
title="我的图册"
|
||||
onClick={() => router.refresh()}
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
window.location.href = "/gallery";
|
||||
}}
|
||||
>
|
||||
<Images className="h-4 w-4" />
|
||||
<span>我的图册</span>
|
||||
</Link>
|
||||
</a>
|
||||
|
||||
{/* 分隔线 (如果有链接或图册按钮,且是管理员) */}
|
||||
{isAdmin && (
|
||||
@ -285,14 +291,17 @@ export function TopNavbar({
|
||||
|
||||
{/* 系统设置(仅管理员可见)*/}
|
||||
{isAdmin && (
|
||||
<Link
|
||||
<a
|
||||
href="/settings"
|
||||
className="flex items-center justify-center h-8 w-8 text-white hover:bg-white/15 hover:text-white rounded-full"
|
||||
title="系统设置"
|
||||
onClick={() => router.refresh()}
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
window.location.href = "/settings";
|
||||
}}
|
||||
>
|
||||
<Settings className="h-4 w-4" />
|
||||
</Link>
|
||||
</a>
|
||||
)}
|
||||
</div>
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user