I added this code to _app.js
Router.events.on('routeChangeComplete', () => {
NProgress.done()
window.scrollTo(0, 0)
})
Everything ok, but scroll doesn't work
next/link already implements this behavior, why'd you need to trigger it another time 馃
Nothing, after each transition my page doesn't scroll to top. I'm using Nextjs Canary 7*
Can you create a minimal reproduction?
@timneutkens Is there any solution for the scroll position; when you refresh the page or click to history back button on your browser?
I'm not sure what you're referring to exactly, could you create a minimal reproduction?
My project is working fine
the example in _app.tsx
public componentDidMount() {
const previousCallback = Router.onRouteChangeComplete;
Router.onRouteChangeComplete = (url: string) => {
if (typeof previousCallback === "function") {
previousCallback(url);
}
window && typeof window === "object" && window.scrollTo && typeof window.scrollTo === "function" && window.scrollTo(0, 0);
};
}
Going to close this
Can you create a minimal reproduction?
@timneutkens Could you provide a minimal reproduction of a working example? Because next/Link is not scrolling to top for me either.