reactjs - 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('/');
}
};
解决方案
我不得不像这样导入:
// works
import Router from "next/router";
// dont
import { Router } from "next/router";
推荐阅读
- android - AppCompatDialogFragment 更改背景颜色
- r - 在 For Loop R 中操作迭代的 CSV 文件
- node.js - 开始在 npm prestart 上运行 cron 作业
- python - 带有 Python 3 和 virtualenv 的 AWS Lambda 无法安装依赖项
- r - R中的ggplot2堆叠条形图
- sql - 优化 Spark 中的 Hive 表加载时间
- javascript - 使用 Javascript 将两个 SVG 元素合二为一?
- javascript - 为什么控制台将 HTML 元素显示为普通对象?
- javascript - backgroundColor 没有做任何事情?
- sql-server - 日期字段上的批量错误,但插入作品 SQL Server