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";
|
"use client";
|
||||||
|
|
||||||
import Link from "next/link";
|
|
||||||
import { useRouter } from "next/navigation";
|
|
||||||
import { memo } from "react";
|
import { memo } from "react";
|
||||||
import { useChatVisibility } from "@/hooks/use-chat-visibility";
|
import { useChatVisibility } from "@/hooks/use-chat-visibility";
|
||||||
import type { Chat } from "@/lib/db/schema";
|
import type { Chat } from "@/lib/db/schema";
|
||||||
@ -40,24 +38,26 @@ const PureChatItem = ({
|
|||||||
onDelete: (chatId: string) => void;
|
onDelete: (chatId: string) => void;
|
||||||
setOpenMobile: (open: boolean) => void;
|
setOpenMobile: (open: boolean) => void;
|
||||||
}) => {
|
}) => {
|
||||||
const router = useRouter();
|
|
||||||
const { visibilityType, setVisibilityType } = useChatVisibility({
|
const { visibilityType, setVisibilityType } = useChatVisibility({
|
||||||
chatId: chat.id,
|
chatId: chat.id,
|
||||||
initialVisibilityType: chat.visibility,
|
initialVisibilityType: chat.visibility,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const handleNavigation = (e: React.MouseEvent) => {
|
||||||
|
e.preventDefault();
|
||||||
|
setOpenMobile(false);
|
||||||
|
window.location.href = `/chat/${chat.id}`;
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SidebarMenuItem>
|
<SidebarMenuItem>
|
||||||
<SidebarMenuButton asChild isActive={isActive}>
|
<SidebarMenuButton asChild isActive={isActive}>
|
||||||
<Link
|
<a
|
||||||
href={`/chat/${chat.id}`}
|
href={`/chat/${chat.id}`}
|
||||||
onClick={() => {
|
onClick={handleNavigation}
|
||||||
setOpenMobile(false);
|
|
||||||
router.refresh();
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
<span>{chat.title}</span>
|
<span>{chat.title}</span>
|
||||||
</Link>
|
</a>
|
||||||
</SidebarMenuButton>
|
</SidebarMenuButton>
|
||||||
|
|
||||||
<DropdownMenu modal={true}>
|
<DropdownMenu modal={true}>
|
||||||
|
|||||||
@ -174,15 +174,18 @@ export function TopNavbar({
|
|||||||
)}
|
)}
|
||||||
|
|
||||||
{/* AI智能精选 */}
|
{/* AI智能精选 */}
|
||||||
<Link
|
<a
|
||||||
href="/featured"
|
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"
|
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智能精选"
|
title="AI智能精选"
|
||||||
onClick={() => router.refresh()}
|
onClick={(e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
window.location.href = "/featured";
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<Sparkles className="h-4 w-4 text-yellow-400" />
|
<Sparkles className="h-4 w-4 text-yellow-400" />
|
||||||
<span>AI精选</span>
|
<span>AI精选</span>
|
||||||
</Link>
|
</a>
|
||||||
|
|
||||||
{/* 精选榜单 */}
|
{/* 精选榜单 */}
|
||||||
<DropdownMenu open={rankingOpen} onOpenChange={setRankingOpen}>
|
<DropdownMenu open={rankingOpen} onOpenChange={setRankingOpen}>
|
||||||
@ -268,15 +271,18 @@ export function TopNavbar({
|
|||||||
</button>
|
</button>
|
||||||
|
|
||||||
{/* 我的图册 */}
|
{/* 我的图册 */}
|
||||||
<Link
|
<a
|
||||||
href="/gallery"
|
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"
|
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="我的图册"
|
title="我的图册"
|
||||||
onClick={() => router.refresh()}
|
onClick={(e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
window.location.href = "/gallery";
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<Images className="h-4 w-4" />
|
<Images className="h-4 w-4" />
|
||||||
<span>我的图册</span>
|
<span>我的图册</span>
|
||||||
</Link>
|
</a>
|
||||||
|
|
||||||
{/* 分隔线 (如果有链接或图册按钮,且是管理员) */}
|
{/* 分隔线 (如果有链接或图册按钮,且是管理员) */}
|
||||||
{isAdmin && (
|
{isAdmin && (
|
||||||
@ -285,14 +291,17 @@ export function TopNavbar({
|
|||||||
|
|
||||||
{/* 系统设置(仅管理员可见)*/}
|
{/* 系统设置(仅管理员可见)*/}
|
||||||
{isAdmin && (
|
{isAdmin && (
|
||||||
<Link
|
<a
|
||||||
href="/settings"
|
href="/settings"
|
||||||
className="flex items-center justify-center h-8 w-8 text-white hover:bg-white/15 hover:text-white rounded-full"
|
className="flex items-center justify-center h-8 w-8 text-white hover:bg-white/15 hover:text-white rounded-full"
|
||||||
title="系统设置"
|
title="系统设置"
|
||||||
onClick={() => router.refresh()}
|
onClick={(e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
window.location.href = "/settings";
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<Settings className="h-4 w-4" />
|
<Settings className="h-4 w-4" />
|
||||||
</Link>
|
</a>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user