首页 > 解决方案 > Next Js Router.push 不是函数错误

问题描述

当我尝试使用 Router.push() 进行重定向时,出现以下错误:

TypeError: next_router__WEBPACK_IMPORTED_MODULE_3__.Router.push is not a function

我正在尝试从 create-react-app 迁移到下一个 js。

const redirectUser = () => {
        if (true) {
            Router.push('/');
        }
    };

标签: reactjsnext.js

解决方案


我不得不像这样导入:

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

推荐阅读