File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change 1+ import { useEffect } from 'react' ;
2+ import { useLocation } from 'react-router' ;
3+
4+ function ScrollToTop ( ) {
5+ const { pathname } = useLocation ( ) ;
6+
7+ useEffect ( ( ) => {
8+ window . scrollTo ( {
9+ top : 0 ,
10+ behavior : 'smooth' , // 부드럽게 스크롤 (즉시 이동은 'auto')
11+ } ) ;
12+ } , [ pathname ] ) ;
13+
14+ return null ;
15+ }
16+
17+ export default ScrollToTop ;
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import { registerSW } from 'virtual:pwa-register';
55import { ReactQueryDevtools } from '@tanstack/react-query-devtools' ;
66import './styles/index.css' ;
77import App from './App.tsx' ;
8+ import ScrollToTop from '@/components/ScrollToTop.tsx' ;
89
910// PWA 서비스 워커 등록
1011const updateSW = registerSW ( {
@@ -24,6 +25,7 @@ const queryClient = new QueryClient();
2425createRoot ( document . getElementById ( 'root' ) ! ) . render (
2526 < QueryClientProvider client = { queryClient } >
2627 < BrowserRouter >
28+ < ScrollToTop />
2729 < App />
2830 </ BrowserRouter >
2931 < ReactQueryDevtools initialIsOpen = { false } />
You can’t perform that action at this time.
0 commit comments