diff --git a/pages/_app.tsx b/pages/_app.tsx index 68bc228..5254b17 100644 --- a/pages/_app.tsx +++ b/pages/_app.tsx @@ -7,6 +7,7 @@ import { SideHeader, } from "../src/components/common/component/component"; import wrapper from "@/src/app/store"; +import ScrollToTop from "@/src/hook/ScrollToTop"; function App({ Component, pageProps }: AppProps) { switch (pageProps.layout) { @@ -78,6 +79,7 @@ function App({ Component, pageProps }: AppProps) { /> 멋쟁이사자처럼 +
@@ -152,6 +154,7 @@ function App({ Component, pageProps }: AppProps) { /> 멋쟁이사자처럼 + diff --git a/src/hook/ScrollToTop.ts b/src/hook/ScrollToTop.ts new file mode 100644 index 0000000..b8cdb02 --- /dev/null +++ b/src/hook/ScrollToTop.ts @@ -0,0 +1,14 @@ +import { useEffect } from "react"; +import { useRouter } from "next/router"; + +/* 리액트 새로고침 시, 최상단으로 이동 */ + +export default function ScrollToTop() { + const { pathname } = useRouter(); + + useEffect(() => { + window.scrollTo(0, 0); + }, [pathname]); + + return null; +}