Skip to content
This repository was archived by the owner on Nov 14, 2024. It is now read-only.

Commit 0fa3c03

Browse files
authored
fix: scroll-to-top
1 parent 2ec2f4b commit 0fa3c03

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/hooks/ScrollToTop.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// ScrollToTop.js
2+
import { useEffect } from 'react';
3+
import { useLocation } from 'react-router-dom';
4+
5+
const ScrollToTop = () => {
6+
const { pathname } = useLocation();
7+
8+
useEffect(() => {
9+
window.scrollTo(0, 0);
10+
}, [pathname]);
11+
12+
return null;
13+
};
14+
15+
export default ScrollToTop;

src/routes/AppRoute.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { Lander } from "../pages/Lander"
1010
import { AppFooter } from "../components/layout/AppFooter"
1111
import { Dashboard } from "../pages/Dashboard"
1212
import { About } from "../pages/About"
13+
import ScrollToTop from "../hooks/ScrollToTop"
1314

1415
export const Route_Items = [
1516
{ name: "Login", link: "/", element: <Lander /> },
@@ -38,6 +39,7 @@ export const AppRoutes = () => {
3839
<div>
3940
<BrowserRouter>
4041
<AppNavbar />
42+
<ScrollToTop />
4143
<Routes>
4244
{
4345
Route_Items.map((item, index) => {

0 commit comments

Comments
 (0)