Error when deploying to Netlify because of 301 redirect with trailing slash #1410
-
Hey there 👋 I'm currently building a website with Nuxt3 and Nuxt Content V2, but I'm facing an issue when deploying to Netlify. Very similarly to the official documentation, I try to fetch a document corresponding to the current browser URL 👇
This works great in dev mode, and in production when navigating using a NuxtLink. After some investigations, this is because there is a 301 redirect from I tried to manually remove this trailing slash.
This partially works : content is now rendered, but there is an ugly flash happening. So I have two questions :
Thank you for the amazing work 🙏 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Problem suddenly disappeared. I am still not sure what was causing it, but 301 redirect to same url with trailing slash is no longer happening. I also added this middleware to avoid all trailing slash : import { withoutTrailingSlash } from 'ufo'
export default defineNuxtRouteMiddleware((to) => {
if (to.path.endsWith('/') && to.path !== '/') {
return navigateTo(withoutTrailingSlash(to.path, true), { redirectCode: 301 })
}
}) Thanks @nathanchase for the tip. ✌️ |
Beta Was this translation helpful? Give feedback.
Problem suddenly disappeared. I am still not sure what was causing it, but 301 redirect to same url with trailing slash is no longer happening.
The solution might be to untick this option in Netlify.
I also added this middleware to avoid all trailing slash :
middleware/noTrailingSlash.global.js
Thanks @nathanchase for the tip.
✌️