Skip to content

Commit

Permalink
feat: ScrollToTop 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
ymj07168 committed Oct 29, 2024
1 parent e9a7798 commit fe519d8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Routers.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import ChallengePage from "./pages/ChallengePage";
import MyPage from "./pages/MyPage";
import SettingPage from "./pages/SettingPage";
import DiscussionPage from "./pages/DiscussionPage";
import ScrollToTop from "./components/common/ScrollToTop";

const Routers = () => {
return (
<BrowserRouter>
<ScrollToTop />
<Routes>
{/* 메인페이지 - 전체 글 목록 / 날짜별 챌린지 목록 */}
<Route element={<MainPage />} path="/" exact />
Expand Down
12 changes: 12 additions & 0 deletions src/components/common/ScrollToTop.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { useEffect } from "react";
import { useLocation } from "react-router-dom";

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

useEffect(() => {
window.scrollTo(0, 0);
}, [pathname]);

return null;
}

0 comments on commit fe519d8

Please sign in to comment.