NextRouter was not mounted. Trying to redirect onApprove from PayPal
Answered
Masai Lion posted this in #help-forum
Masai LionOP
I want to redirect users to "success/[id]" after a successful PayPal payment using dynamic links. The id, which corresponds to the orderId from PayPal, should replace the placeholder. For instance, it should look like "success/orderid?=skdaaisjda". I also need to store this data locally. However, when attempting this, I encounter an error:
Error: NextRouter was not mounted. For more information, refer to https://nextjs.org/docs/messages/next-router-not-mounted.
This issue arises in my code at line 84 in the file components\Cart.tsx.
https://github.com/yoboywhat/Paypal-onApprove-Redirect-Issue-21-02-2024-/tree/main
Error: NextRouter was not mounted. For more information, refer to https://nextjs.org/docs/messages/next-router-not-mounted.
This issue arises in my code at line 84 in the file components\Cart.tsx.
https://github.com/yoboywhat/Paypal-onApprove-Redirect-Issue-21-02-2024-/tree/main
Answered by Polar bear
If you are using app router, make sure you import useRouter from “next/navigation†and NOT from “next/routerâ€
8 Replies
Polar bear
If you are using app router, make sure you import useRouter from “next/navigation†and NOT from “next/routerâ€
Answer
@Polar bear If you are using app router, make sure you import useRouter from “next/navigation†and NOT from “next/routerâ€
Masai LionOP
error doesnt appear no more but it isnt redirecting, gotta check that
i should try pushing the route directly on onApprove
wait no, but otherwise I cant take order id
Masai LionOP
works now
@Polar bear If you are using app router, make sure you import useRouter from “next/navigation†and NOT from “next/routerâ€
Asiatic Lion
Thanks. it also works on my end. ðŸ‘