Skip to content

Commit d51c0b6

Browse files
committed
fixed link opening at scroll position problem
1 parent d2f1f22 commit d51c0b6

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/App.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,22 @@ import {
1212
HashRouter as Router,
1313
Route,
1414
Routes,
15-
Navigate
15+
Navigate,
16+
useLocation
1617
} from "react-router-dom";
1718
import "./App.css";
1819
import "bootstrap/dist/css/bootstrap.min.css";
1920

21+
function ScrollToTop() {
22+
const { pathname } = useLocation();
23+
24+
useEffect(() => {
25+
window.scrollTo(0, 0);
26+
}, [pathname]);
27+
28+
return null;
29+
}
30+
2031
function App() {
2132
const [load, upadateLoad] = useState(true);
2233

@@ -30,6 +41,7 @@ function App() {
3041

3142
return (
3243
<Router>
44+
<ScrollToTop />
3345
<LoadingAnimation load={load} />
3446
<div className="App" id={load ? "no-scroll" : "scroll"}>
3547
<Navbar />

0 commit comments

Comments
 (0)