From 4c4eb60a3dbc3ae882e6f87f3bc53d31f2583432 Mon Sep 17 00:00:00 2001 From: al Date: Mon, 12 Aug 2024 21:31:50 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=84=E7=90=86=E5=B8=83=E5=B1=80=E4=B8=8D?= =?UTF-8?q?=E5=90=8C=E6=AD=A5=E9=94=99=E4=BD=8D=E9=97=AE=E9=A2=98=E5=92=8C?= =?UTF-8?q?=E8=A7=86=E9=A2=91=E9=AB=98=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/layout.js | 18 +++++++++++++++--- app/page.js | 4 ++-- utils/tools/handleFuns.js | 5 +++-- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/app/layout.js b/app/layout.js index a3be66c..907ab8a 100644 --- a/app/layout.js +++ b/app/layout.js @@ -1,6 +1,7 @@ "use client"; import { Inter } from "next/font/google"; -import React from "react"; +import React, { useEffect } from "react"; +import { usePathname } from "next/navigation"; import "./globals.css"; import BottomNav from "../components/BottomNav"; import { Provider } from "react-redux"; @@ -31,6 +32,17 @@ const metadata = { // userScalable: 0, // }; export default function RootLayout({ children }) { + const pathname = usePathname(); + useEffect(()=>{ + const timer = setTimeout(() => { + window.scrollTo({ + top: 0, + left: 0, + behavior: "smooth", // 可选,平滑滚动效果 + }); + clearTimeout(timer); + }, 100); + },[pathname]) return ( {/* */} {/* */} - + {/* */} {/* */} {/* */} @@ -199,7 +211,7 @@ export default function RootLayout({ children }) { )} {/* {children} */} -