관리자 화면 스크롤 복원
This commit is contained in:
parent
d939253b3f
commit
a5a2e2ea78
4 changed files with 47 additions and 1 deletions
|
|
@ -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>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue