Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { gsap } from "gsap";
import { ScrollTrigger } from "gsap/ScrollTrigger";
import { useEffect, useRef } from "react";
import { Route, Routes } from "react-router-dom";
import ScrollToTop from "./components/ScrollTop";
import Toastify from "./components/Toastify";
import { CreditProvider } from "./context/CreditContext";
import DefaultLayout from "./layouts/DefaultLayout";
Expand Down Expand Up @@ -40,6 +41,7 @@ function App() {
return (
<CreditProvider>
<Toastify />
<ScrollToTop />
<Routes>
<Route index element={<Landing />} />
<Route path="/" element={<DefaultLayout />}>
Expand Down
14 changes: 14 additions & 0 deletions src/components/ScrollTop.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { useEffect } from "react";
import { useLocation } from "react-router-dom";

export default function ScrollToTop() {
const { pathname } = useLocation();

useEffect(() => {
if (pathname) {
window.scrollTo(0, 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이런 이슈가 있었군요... 스크롤을 초기화해주는 코드인가용?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

페이지가 이동할 때 (path가 변경될 때)마다 페이지 상단으로 이동하게 해주는 코드입니당~

}
}, [pathname]);

return null;
}