When using the App Router, we cannot import the router from next/router. Instead, we must use: import { useRouter } from "next/navigation";
.
In this case, the router.push function accepts two parameters: router.push(href, options);
So, in my case, I need to update my code like this:
useEffect(() => {
if (!pageNumber || pageNumber === null || pageNumber === "") {
router.push(`?pageNumber=1`, { shallow: true, scroll: false });
}
}, []);
With this change, everything works perfectly, and the page no longer scrolls to the top.