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)

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay