Skip to content

Commit

Permalink
feat : 스크롤 상단 처리 (#29)
Browse files Browse the repository at this point in the history
feat : 스크롤 상단 처리 (#29)
  • Loading branch information
klmhyeonwoo authored Jun 25, 2023
2 parents 7e52ac8 + 4461a17 commit 9dbd6a9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -78,6 +79,7 @@ function App({ Component, pageProps }: AppProps) {
/>
<title> 멋쟁이사자처럼 </title>
</Head>
<ScrollToTop />
<GlobalStyles />
<Header />
<Component {...pageProps} />
Expand Down Expand Up @@ -152,6 +154,7 @@ function App({ Component, pageProps }: AppProps) {
/>
<title> 멋쟁이사자처럼 </title>
</Head>
<ScrollToTop />
<GlobalStyles />
<SideHeader />
<Component {...pageProps} />
Expand Down
14 changes: 14 additions & 0 deletions src/hook/ScrollToTop.ts
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit 9dbd6a9

Please sign in to comment.