From a8965119ce44308f391200a45d316b3167f2f5ae Mon Sep 17 00:00:00 2001 From: mtvpls Date: Sun, 30 Nov 2025 21:33:05 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=9D=E8=AF=95=E4=BF=AE=E5=A4=8D=E5=AF=BC?= =?UTF-8?q?=E8=88=AA=E5=88=87=E6=8D=A2=E9=98=BB=E5=A1=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .next | 1 + .vscode/launch.json | 17 +++++++++++++ src/components/MobileBottomNav.tsx | 12 ++++++--- src/components/MobileHeader.tsx | 2 ++ src/components/Sidebar.tsx | 40 +++++++++++------------------- 5 files changed, 43 insertions(+), 29 deletions(-) create mode 120000 .next create mode 100644 .vscode/launch.json diff --git a/.next b/.next new file mode 120000 index 0000000..27e4e2f --- /dev/null +++ b/.next @@ -0,0 +1 @@ +/.next \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..fef730b --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,17 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "request": "launch", + "name": "Launch Program", + "skipFiles": [ + "/**" + ], + "program": "${workspaceFolder}/start" + } + ] +} \ No newline at end of file diff --git a/src/components/MobileBottomNav.tsx b/src/components/MobileBottomNav.tsx index 3932ec3..43b29aa 100644 --- a/src/components/MobileBottomNav.tsx +++ b/src/components/MobileBottomNav.tsx @@ -4,7 +4,7 @@ import { Cat, Clover, Film, Home, Radio, Star, Tv } from 'lucide-react'; import Link from 'next/link'; -import { usePathname } from 'next/navigation'; +import { usePathname, useSearchParams } from 'next/navigation'; import { useEffect, useState } from 'react'; interface MobileBottomNavProps { @@ -16,9 +16,14 @@ interface MobileBottomNavProps { const MobileBottomNav = ({ activePath }: MobileBottomNavProps) => { const pathname = usePathname(); + const searchParams = useSearchParams(); - // 当前激活路径:优先使用传入的 activePath,否则回退到浏览器地址 - const currentActive = activePath ?? pathname; + // 直接使用当前路由状态,确保立即响应路由变化 + const getCurrentFullPath = () => { + const queryString = searchParams.toString(); + return queryString ? `${pathname}?${queryString}` : pathname; + }; + const currentActive = activePath ?? getCurrentFullPath(); const [navItems, setNavItems] = useState([ { icon: Home, label: '首页', href: '/' }, @@ -98,6 +103,7 @@ const MobileBottomNav = ({ activePath }: MobileBottomNavProps) => { > {
{
{siteName} diff --git a/src/components/Sidebar.tsx b/src/components/Sidebar.tsx index 04f006c..7063300 100644 --- a/src/components/Sidebar.tsx +++ b/src/components/Sidebar.tsx @@ -4,7 +4,7 @@ import { Cat, Clover, Film, Home, Menu, Radio, Search, Star, Tv } from 'lucide-react'; import Link from 'next/link'; -import { usePathname, useRouter, useSearchParams } from 'next/navigation'; +import { usePathname, useSearchParams } from 'next/navigation'; import { createContext, useCallback, @@ -54,7 +54,6 @@ declare global { } const Sidebar = ({ onToggle, activePath = '/' }: SidebarProps) => { - const router = useRouter(); const pathname = usePathname(); const searchParams = useSearchParams(); // 若同一次 SPA 会话中已经读取过折叠状态,则直接复用,避免闪烁 @@ -92,19 +91,14 @@ const Sidebar = ({ onToggle, activePath = '/' }: SidebarProps) => { const [active, setActive] = useState(activePath); useEffect(() => { - // 优先使用传入的 activePath - if (activePath) { - setActive(activePath); - } else { - // 否则使用当前路径 - const getCurrentFullPath = () => { - const queryString = searchParams.toString(); - return queryString ? `${pathname}?${queryString}` : pathname; - }; - const fullPath = getCurrentFullPath(); - setActive(fullPath); - } - }, [activePath, pathname, searchParams]); + // 立即根据当前路径更新状态,不等待页面加载 + const getCurrentFullPath = () => { + const queryString = searchParams.toString(); + return queryString ? `${pathname}?${queryString}` : pathname; + }; + const fullPath = getCurrentFullPath(); + setActive(fullPath); + }, [pathname, searchParams]); const handleToggle = useCallback(() => { const newState = !isCollapsed; @@ -116,10 +110,6 @@ const Sidebar = ({ onToggle, activePath = '/' }: SidebarProps) => { onToggle?.(newState); }, [isCollapsed, onToggle]); - const handleSearchClick = useCallback(() => { - router.push('/search'); - }, [router]); - const contextValue = { isCollapsed, }; @@ -203,7 +193,11 @@ const Sidebar = ({ onToggle, activePath = '/' }: SidebarProps) => {