From e5cab79993ef6a4f26af5e9a25cfed076f3d471d Mon Sep 17 00:00:00 2001 From: mtvpls Date: Mon, 5 Jan 2026 14:32:32 +0800 Subject: [PATCH] =?UTF-8?q?play=E5=92=8Clive=E8=B1=81=E5=85=8D=E8=BF=9B?= =?UTF-8?q?=E5=BA=A6=E6=9D=A1=E5=8F=82=E6=95=B0=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/TopProgressBar.tsx | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/components/TopProgressBar.tsx b/src/components/TopProgressBar.tsx index e458cd3..c351ab1 100644 --- a/src/components/TopProgressBar.tsx +++ b/src/components/TopProgressBar.tsx @@ -1,7 +1,7 @@ 'use client'; import { useEffect, useRef } from 'react'; -import { usePathname, useRouter } from 'next/navigation'; +import { usePathname, useSearchParams, useRouter } from 'next/navigation'; import NProgress from 'nprogress'; // 创建全局钩子来拦截 router @@ -9,6 +9,7 @@ let globalRouterRef: any = null; export default function TopProgressBar() { const pathname = usePathname(); + const searchParams = useSearchParams(); const router = useRouter(); const isNavigatingRef = useRef(false); const previousPathnameRef = useRef(pathname); @@ -34,7 +35,11 @@ export default function TopProgressBar() { router.push = function (...args: Parameters) { const targetUrl = args[0] as string; const targetPathname = new URL(targetUrl, window.location.href).pathname; - if (targetPathname !== previousPathnameRef.current) { + const currentPathname = window.location.pathname; + + // /play 和 /live 页面:参数变化也显示进度条 + // 其他页面:仅路径变化时显示进度条 + if (currentPathname === '/play' || currentPathname === '/live' || targetPathname !== previousPathnameRef.current) { isNavigatingRef.current = true; NProgress.start(); } @@ -45,7 +50,11 @@ export default function TopProgressBar() { router.replace = function (...args: Parameters) { const targetUrl = args[0] as string; const targetPathname = new URL(targetUrl, window.location.href).pathname; - if (targetPathname !== previousPathnameRef.current) { + const currentPathname = window.location.pathname; + + // /play 和 /live 页面:参数变化也显示进度条 + // 其他页面:仅路径变化时显示进度条 + if (currentPathname === '/play' || currentPathname === '/live' || targetPathname !== previousPathnameRef.current) { isNavigatingRef.current = true; NProgress.start(); } @@ -121,7 +130,7 @@ export default function TopProgressBar() { isNavigatingRef.current = false; } previousPathnameRef.current = pathname; - }, [pathname]); + }, [pathname, searchParams]); return null; }