DEV Community

Cover image for UseRouter import from next/navigation or next/router in App Router Next JS?
Vivek
Vivek

Posted on

UseRouter import from next/navigation or next/router in App Router Next JS?

Hi devs, in this article we will learn which solution is better for us.
So many developers facing issue while using useRouter in next JS.

import { useRouter } from "next/router";

 const router = useRouter();
Enter fullscreen mode Exit fullscreen mode

The above import is not working in next JS when we are using app router.

So as documentation next js allow useRouter from next/navigation in App Router.
Here is the way of importing the useRouter in App Router.

import { useRouter } from "next/navigation";

  const router = useRouter();

Enter fullscreen mode Exit fullscreen mode

Thank you for reading. That’s all for today.

Top comments (0)