I want to redirect a user in Next without using <Link>. React Router has useNavigate(), so does Next Router have anything similar?

Viewed 29

I want to redirect users in NextJS similar to how you can use useNavigate(). <Link /> is not good enough for this, because I want the user to be immediately redirected.

1 Answers

I suppose you would be looking for the useRouter hook to access the router object and issue an imperative navigation action.

Example:

const router = useRouter();

...

router.replace(targetInAppUrl);

See router.push or router.replace for more details.

Related