I am using Next Js for creating my website and while I am using next/link or next/router to change the path of the route it the scroll web site doesn't go to top of the page it remains in the same location where it was there before, and I know by default next/link and next/router has scroll top behaviour but it does not work for me, and I used custom componenent to do it but a gain it does not work
import { useRouter } from "next/router";
const ScrollTop = () => {
const router = useRouter();
const path = router.pathname;
useEffect(() => {
try {
window.scroll({
top: 0,
left: 0,
behavior: 'smooth',
});
console.log("scrool try ");
} catch (error) {
console.log("scrool catch ");
window.scrollTo(0, 0);
}
} , [path])
return null;
}
export default ScrollTop;