英文:
Nuxt 3 route redirect on page and public directory with the same name
问题
我有一个名为 foo.vue 的页面和一个名为 foo 的公共目录。
pages
  foo.vue
public
  foo
当我在本地加载页面时,使用 "/localhost:3000/foo",页面会加载,但浏览器会在末尾添加斜杠,并从原始 URL 重定向到带斜杠的 URL(301 重定向)。
当部署到 Vercel 时,可以使用相同的 URL 加载页面,但我看不到 301 重定向,并且不会添加斜杠。
不管有没有斜杠,我希望在开发和生产环境中的行为一致。
在我的 nuxt.config.ts 文件中,唯一可疑的行是:
ssr: process.env.NODE_ENV !== 'development',
我添加了这行代码以使一些 Vuetify 组件正常工作。
我阅读了这个 Nuxt 问题 几次,但没有找到解决方法。
那么,如何在开发和生产环境中获得一致的斜杠或无斜杠行为?
英文:
I have a foo.vue page and a foo directory under public.
pages
  foo.vue
public
  foo
When I load the page locally with "/localhost:3000/foo", the page is loaded, but the browser adds a trailing slash at the end, and there is a 301 redirect from the original URL to the one with the slash.
When it's deployed to Vercel, the page can also be loaded with the same URL, but I don't see 301 redirect and no trailing slash is added.
Either with or without trailing slash, I want dev and prod behave consistently.
In my nuxt.config.ts, the only suspicious line is,
ssr: process.env.NODE_ENV !== 'development',
I added this line to make some Vuetify components happy.
I read this Nuxt issue a few times, didn't figure out a fix.
So, how do I get consistent trailing slash or no slash on dev and prod?
答案1
得分: 1
尝试将 pages/foo.vue 更改为 pages/foo/index.vue。
英文:
Try changing pages/foo.vue to pages/foo/index.vue
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论