Skip to content

Commit

Permalink
Feat: 페이지 이동 시 상단으로 이동하는 기능 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
hankim0904 committed Apr 2, 2024
1 parent 25eabed commit e4ce028
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions co-kkiri/src/PageRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import Navigation from "./layouts/Navigation";
import GoogleAuth from "./pages/Auth/GoogleAuth";
import AuthListener from "./components/commons/AuthListener";
import GithubAuth from "./pages/Auth/GithubAuth";
import PageScrollTop from "./components/commons/PageScrollTop";

const {
HOME_PATH,
Expand All @@ -35,6 +36,7 @@ const PageRouter = () => {
return (
<Router>
<AuthListener />
<PageScrollTop />
<Routes>
<Route path="/" element={<Navigation />}>
<Route path={HOME_PATH} element={<Home />} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default function ScrollToTop() {

if (!scrollY) return;

if (scrollY > 200) {
if (scrollY > 400) {
setIsVisible(true);
} else {
setIsVisible(false);
Expand Down
11 changes: 11 additions & 0 deletions co-kkiri/src/components/commons/PageScrollTop.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { useEffect } from "react";
import { useLocation } from "react-router-dom";

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

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

0 comments on commit e4ce028

Please sign in to comment.