When I try to redirect using Router.push() I get the following error:
TypeError: next_router__WEBPACK_IMPORTED_MODULE_3__.Router.push is not a function
I am trying to migrate from create-react-app to next js.
const redirectUser = () => {
if (true) {
Router.push('/');
}
};
I had to import like so:
// works
import Router from "next/router";
// dont
import { Router } from "next/router";
Don't add curly bracket while importing Router from next/router
Use this:
import Router from "next/router";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With