79493257

Date: 2025-03-07 19:10:44
Score: 1.5
Natty:
Report link

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.

Reasons:
  • Blacklisted phrase (0.5): I need
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Starts with a question (0.5): When
  • Low reputation (1):
Posted by: Giorgos Karras