Next.js 13.4.5 部署:重定向将“.txt”附加到URL中的页面名称

huangapple go评论72阅读模式
英文:

Next.js 13.4.5 deployment: Redirects appending ".txt" to page names in URL

问题

我目前在我的Next.js 13.4.5部署到Firebase中遇到了重定向问题。我已经配置了我的Next.js应用程序,使其以静态导出的方式输出,使用了下面在我的next.config.js文件中的配置:

/** @type {import('next').NextConfig} */
const nextConfig = {
    output: 'export',
}

module.exports = nextConfig

然而,在将我的应用程序部署到Firebase后,我注意到重定向会在URL中的页面名称后附加“.txt”。例如,而不是重定向到http://localhost:3000/dashboard,URL变为http://localhost:3000/dashboard.txt。

我期望重定向能够在Next.js中使用router.push()作为客户端重定向正常工作,而不会修改URL,添加“.txt”扩展名。

我已经检查了我的重定向配置,它们似乎是正确的。是否在我的部署设置或配置中有我忽略的东西可能导致了这个问题?

英文:

I'm currently facing an issue with redirects in my Next.js 13.4.5 deployment to Firebase. I have configured my Next.js application to output as a static export using the following configuration in my next.config.js file:

/** @type {import('next').NextConfig} */
const nextConfig = {
    output: 'export',
}

module.exports = nextConfig

However, after deploying my application to Firebase, I noticed that the redirects are appending ".txt" to the page names in the URL. For example, instead of redirecting to http://localhost:3000/dashboard, the URL becomes http://localhost:3000/dashboard.txt.

I expected the redirect to function properly as a client-side redirect using router.push() in Next.js, without modifying the URL with the ".txt" extension.

I have checked my redirect configurations, and they seem to be correct. Is there something I'm missing in my deployment setup or configuration that could be causing this issue?

答案1

得分: 1

很抱歉,自 Next.js 13.3.0 以来,这个错误一直存在。简而言之,output: 'export' 不支持动态路由。在 GitHub 上有一个已记录的错误。您可以查看更多信息以及像我一样的解决方法。
https://github.com/vercel/next.js/issues/48022

编辑:我刚刚注意到,在您的问题中,示例没有动态路由。我自己遇到了这个问题,所以理所当然地认为它是一个动态路由。希望我的答案仍然有所帮助。

英文:

Unfortunately, this bug has been a thing since nextjs 13.3.0. In short, output: 'export' doesn't support dynamic routing. There is a bug logged in github. You may look it up for more information and work arounds like I did.
https://github.com/vercel/next.js/issues/48022

edit: I just noticed that in your question, the exemple does not have a dynamic route. I was having this issue myself so I took for granted the fact it was a dynamic route. Hope my answer help regardless

huangapple
  • 本文由 发表于 2023年6月19日 03:54:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/76502307.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定