관리자 화면 스크롤 복원

This commit is contained in:
Yun Chan 2026-07-03 20:27:54 +09:00
parent d939253b3f
commit a5a2e2ea78
4 changed files with 47 additions and 1 deletions

View file

@ -15,7 +15,7 @@
AuthContext . .
===================================================================== */
import type { ReactNode } from "react";
import { useEffect, type ReactNode } from "react";
import { BrowserRouter, Navigate, Route, Routes, useLocation } from "react-router-dom";
import { AuthProvider, canAccessRole, initialPathForUser, useAuth, roleHomePath, type AuthUser, type Role } from "./lib/auth";
@ -129,6 +129,18 @@ function RootRedirect() {
return <Navigate to={user ? initialPathForUser(user) : "/login"} replace />;
}
function ScrollToTopOnPathChange() {
const { pathname } = useLocation();
useEffect(() => {
window.scrollTo({ top: 0, left: 0, behavior: "auto" });
document.documentElement.scrollTop = 0;
document.body.scrollTop = 0;
}, [pathname]);
return null;
}
function AppRoutes() {
return (
<PendingApprovalGate>
@ -298,6 +310,7 @@ export default function App() {
return (
<BrowserRouter>
<AuthProvider>
<ScrollToTopOnPathChange />
<AppRoutes />
</AuthProvider>
</BrowserRouter>