Skip to content

Commit

Permalink
Merge pull request #334 from love-sonkar/scrolltotop
Browse files Browse the repository at this point in the history
fixes footer link navigates to home with scroll top
  • Loading branch information
ArslanYM authored Sep 24, 2023
2 parents 353bc9e + 00c71b4 commit 56d21da
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions web/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@ import { BrowserRouter, Routes, Route } from "react-router-dom";
import { Home, Contributors, Guide, ProjectList } from "./pages";
import MasterLayout from "./layouts";
import { IssueList } from "./pages/Issues/IssueList";
import ScrollTop from "./components/ScrollTop";

function App() {
return (
<BrowserRouter>
<MasterLayout>
<ScrollTop>
<Routes>
<Route path="/" element={<Home />} />
<Route path="/contributors" element={<Contributors />} />
<Route path="/Docs" element={<Guide />} />
<Route path="/projects" element={<ProjectList />} />
<Route path="/issues" element={<IssueList />} />
</Routes>
</ScrollTop>
</MasterLayout>
</BrowserRouter>
);
Expand Down
20 changes: 20 additions & 0 deletions web/src/components/ScrollTop.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import {useEffect} from 'react'
import { useLocation } from 'react-router-dom'


const ScrollTop = ({children}) => {
const location = useLocation()
useEffect(() => {
window.scrollTo({
top: 0,
left: 0,
behavior: "smooth"
})
}, [location])

return (
<>{children}</>
)
}

export default ScrollTop

1 comment on commit 56d21da

@vercel
Copy link

@vercel vercel bot commented on 56d21da Sep 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

starter-hive – ./

starter-hive-git-main-arslanym.vercel.app
starter-hive.vercel.app
starter-hive-arslanym.vercel.app

Please sign in to comment.