-
-
Notifications
You must be signed in to change notification settings - Fork 156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Scroll to top on route change #132
Comments
@notangelmario The solution should probably similar to what they recommend in react-router: https://reactrouter.com/web/guides/scroll-restoration/scroll-to-top import { useEffect } from "react";
import { useLocation } from "wouter";
export default function ScrollToTop() {
const [ pathname ] = useLocation();
useEffect(() => {
window.scrollTo(0, 0);
}, [pathname]);
return null;
} |
Thank you very much! |
Just wanted to note that the solution above is outdated: import { useEffect } from "react";
import { useLocation } from "wouter";
export default function ScrollToTop() {
const [ pathname ] = useLocation();
useEffect(() => {
window.scrollTo(0, 0);
}, [pathname]);
return null;
} Simply change the curly braces to square brackets and you are set! |
I've updated my comment, thanks for spotting the typo @xav-ie |
JannekS
added a commit
to JannekS/hcs2023-travelblog-react
that referenced
this issue
Jun 10, 2023
implement solution from molefrog/wouter#132
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How can we make the page scroll back to top on route change? Is there a function we can hook into the Link component? Some kind of option or something
The text was updated successfully, but these errors were encountered: