Skip to content

Commit

Permalink
fix scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
LukePrior committed Aug 26, 2023
1 parent 81925b2 commit 0f0f626
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import defaultPlantData from './assets/defaultPlants.json'
import Background from './components/Background';
import { config } from './logic/constants';
import Debug from './pages/Debug';
import ScrollToTop from './components/ScrollToTop'

function App() {
useEffect(() => {
Expand All @@ -27,6 +28,7 @@ function App() {
<div className='bg-transparent z-50'>
<Background />
<HashRouter>
<ScrollToTop />
<Routes>
<Route path='/' element={<Home />} />
<Route path='/garden' element={<Garden />} />
Expand Down
12 changes: 12 additions & 0 deletions src/components/ScrollToTop.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { useEffect } from "react";
import { useLocation } from "react-router-dom";

export default function ScrollToTop() {
const { pathname } = useLocation();

useEffect(() => {
window.scrollTo(0, 0);
}, [pathname]);

return null;
}

0 comments on commit 0f0f626

Please sign in to comment.