Next.js: Next Js Router.push is not a function error

Created on 1 Mar 2019  路  2Comments  路  Source: vercel/next.js

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 (redirectToSignin) {
            Router.push({
                pathname: "/user/signin",
                query: { message: "Please signin to view profile" }
            });
        }
    };

Most helpful comment

I had to import like so:

// works
import Router from "next/router";
// dont
import { Router } from "next/router";

All 2 comments

Not sure what's going on here. Please follow the issue template and provide a full reproduction.

I had to import like so:

// works
import Router from "next/router";
// dont
import { Router } from "next/router";
Was this page helpful?
0 / 5 - 0 ratings