Next.js 刷新后获取 JS 资源时出现 404 错误

mac*_*ost 15 next.js

我正在运行 Next.js 开发服务器。当我转到第 1 页,然后单击第 2 页的链接时,效果很好。(澄清一下,我没有使用asNext<Link>标签的属性,只是使用常规的旧href。)

但是,如果我刷新第 2 页,页面本身会加载,所有图像也会加载......但所有 Javascript 文件都会失败并显示 404:

http://localhost:3000/page2/_next/static/chunks/main.js?ts=1612664646023 net::ERR_ABORTED 404(未找到)2localhost/:196 GET

http://localhost:3000/page2/_next/static/development/_buildManifest.js?ts=1612664646023 net::ERR_ABORTED 404(未找到)2localhost/:1 GET

http://localhost:3000/page2/_next/static/chunks/webpack.js?ts=1612664646023 net::ERR_ABORTED 404(未找到)7localhost/:196 GET

http://localhost:3000/page2/_next/static/chunks/main.js?ts=1612664646023 net::ERR_ABORTED 404(未找到)

有谁知道我能做什么来解决这个问题?

小智 6

继承代码遇到类似的问题,搜索一百万次,这是最高的结果。我对所有其他沮丧的开发人员的回答是,检查您的“链接”和“router.push()”,特别是如果您使用自定义路由器。Link 和 router.push() 应指向服务器 url。您可以传递“as”来屏蔽浏览器的 URL。