Skip to content

Commit dbe2c22

Browse files
committed
fix: scroll to top on page navigation
1 parent 39834eb commit dbe2c22

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

frontend/src/App.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { SemanticSearchPage, DependencyAnalysisPage, ImpactPredictionPage, CodeS
1515
import { DockerSetupPage, SelfHostingPage } from './pages/deployment';
1616
import { APIOverviewPage, APIRepositoriesPage, APISearchPage, APIAnalysisPage } from './pages/api';
1717
import { GitHubCallbackPage } from './pages/GitHubCallbackPage';
18+
import { ScrollToTop } from './components/ScrollToTop';
1819

1920
function ProtectedRoute({ children }: { children: React.ReactNode }) {
2021
const { user, loading } = useAuth();
@@ -122,6 +123,7 @@ export function App() {
122123
>
123124
<TooltipProvider>
124125
<BrowserRouter>
126+
<ScrollToTop />
125127
<AuthProvider>
126128
<AppRoutes />
127129
</AuthProvider>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { useEffect } from 'react'
2+
import { useLocation } from 'react-router-dom'
3+
4+
export function ScrollToTop() {
5+
const { pathname } = useLocation()
6+
7+
useEffect(() => {
8+
window.scrollTo(0, 0)
9+
}, [pathname])
10+
11+
return null
12+
}

0 commit comments

Comments
 (0)