Home > Back-end >  I want to redirect a user in Next without using <Link>. React Router has useNavigate(), so doe
I want to redirect a user in Next without using <Link>. React Router has useNavigate(), so doe

Time:09-07

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.

CodePudding user response:

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