You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Next.js报错求助:无法解析‘next-router’模块

解决Module not found: Can't resolve 'next-router'错误

你犯了一个常见的路径错误:Next.js不存在next-router这个包,useRouter的正确导入路径取决于你使用的路由模式:

情况1:使用Pages Router(项目有pages文件夹)

直接从next/router导入:

import { useRouter } from 'next/router'

情况2:使用App Router(项目是app文件夹,Next.js 13默认)

从next/navigation导入:

import { useRouter } from 'next/navigation'

注意:App Router的useRouter API和Pages Router有差异,比如无法直接获取query对象,需要用useParams()或useSearchParams()来获取路由参数。

你的package.json里已经正确安装了Next.js 13.0.6,不需要额外安装任何包,只要修正导入路径即可解决这个错误。

内容的提问来源于stack exchange,提问作者hrd

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.09 04:25:18