#dynamic routes working but have 404 status code
1 messages · Page 1 of 1 (latest)
Hi, does this happen on devserver? locally build preview? or deployed build?
hey! good question, i was about to add that 🙂
only on staging site
take a look in netwrok tab
@sour radish
so yeh deployed build on netlify
Does this happen on every page? @foggy flint
every instance of this '/packages/[ref]/[slug] route
Do you have any custom Nitro Configuration?
no
And this does not happen on Dev Mode, right?
right
Can you show me npx nuxi info output & your nuxt.config?
config:
okay, delete the message. Just leaked your Directus Token.
```- Operating System: Darwin
- Node Version:
v16.12.0 - Nuxt Version:
3.2.0 - Nitro Version:
2.2.2 - Package Manager:
[email protected] - Builder:
vite - User Config:
app,modules,buildModules,routeRules,css,image,runtimeConfig,googleFonts,sitemap,directus - Runtime Modules:
@funken-studio/[email protected],@nuxtjs/[email protected],[email protected],@pinia/[email protected],@nuxtjs/[email protected],@nuxt/[email protected],[email protected] - Build Modules:
@nuxtjs/[email protected], `@nuxtjs/sitemap```
oops true ! 😆
Does one of the modules can cause the error?
hmm well i just saw i can get rid of the sitemap one. trying that
Are you prerendering the pages?
yes , ssr is default value so true
And you are deploying with nuxi generate?
yes
Okay, can you show me your Dynamic Page?
Does it happen on other routes too? Or only on this?
no, only this
the only other 404 is any invalid route, which returns my error.vue component in the root directory
Yeah that's interesting since you've said that the page itself is rendering fine. It's just netlify server returning 404. It looks to me that netlify isn't configured properly, meaning that it does not detect this route to be there. Sometimes for static sites you have to tell netlify that every subroute is valid, even though you don't have html files in there.
Can you do a nuxt generate locally and check whether there are html files in there?
Maybe you try to deploy on an other service?
ok with npx nuxi generate?
Yes
Do you have another dynamic route in your project? Or is this the only one
check if thats the same there
and check the build logs, it should exactly list which pages are being generated
How do you mean that?
They doesn't exist?
Can you show us the output of nuxi generate
If you try to test it local, using serve or something else. Do you also get the 404?
no i dont
How do you start it locally?
yarn dev
Static site generation (SSG) with ssr: true pre-renders routes of your application at build time. (This is the default behaviour when running nuxi generate.) It will also generate /200.html and /404.html single-page app fallback pages, which can render dynamic routes or 404 errors on the client (though you may need to configure this on your static host).
@foggy flint Are you using the nitro netlify preset?
hmm no sounds good!
Add this to your nuxt.config
nitro: {
preset: 'netlify'
}
But actually, this should be zero-config.
So I think the fallback routes are our problem
If this doesnt change anything, try to locally start the static output.
npx serve -s .output/public
Same problem
ah you checked?
Yes
serving static output, no 404!
okay, its a deployment problem.
I think the nitro netlify preset needs more specific configuration for dynamic routes.
Let me check something.
ok
Can you show me your netlify configuration, so the configured commands?
How does Netlify start it?
oh after the build ? hmm
yes
And a 404.html?
yup
okay
not sure how netlify starts it. Maybe i should try vercel
You can try that, and it will certainly work. But still, it's not right.
ok sso thinknig it through, dynamic routes obviously cant get prerendered. So as in my local build , they should be rendered in real time and not have 404 status
Maybe you make them ClientOnly if this is not a problem
But in every case, this problem should be documented.
Yes
I will create an example on GitHub and try to find a solution for this issue.
thanks so much
@foggy flint Actually, when doing nuxt generate, also dynamic routes are getting prerendered. For example, my [slug].vue blog page looks like this on build:
ℹ Prerendering 7 initial routes with crawler
├─ / (1756ms)
├─ /blog (1608ms)
├─ /contact (941ms)
├─ /datenschutz (1028ms)
├─ /200.html (3ms)
├─ /404.html (2ms)
├─ /robots.txt (2ms)
├─ /about (1001ms)
├─ /blog/how-to-integrate-calendly-in-nuxt-3 (1456ms)
├─ /blog/how-to-create-a-nuxt-3-headless-website-with-wordpress (1465ms)
and they are like rendered as html pages inside my output.
@foggy flint How do you named the slug file?
Try to name it just: [slug].vue
it used to be like that
Any reasons why there is double [[ref]]?
Okay but optional + something dynamic inside idk if that works, maybe that's the reason
ok going back to simple naming now
I will try to reproduce this error with netlify
Not really
When he trys to serve it locally it works
I know
I think its a problem with the Netlify configuration
but the generator may not catch it as something to generate
Hmm
because you should have .html files
and because you don't, netlify throws 404 but still shows the page because of nuxt maybe generating it dynamically client side
yes right, but how are yours getting generated. the slug title are coming from links in the site right
I have the same problem
I can reproduce it
With a normal dynamic page @wispy prawn
Okay thanks for trying out.
@foggy flint can you try one thing. open a url with view-source: before in chrome and try to search for some of your page content
Is that html actually in there? Or is it just an empty page
Trying to check if your page gets delivered empty and the client renders it. Because that would be very bad for SEO, being SPA-mode.
ok
In my example it does not create a html file for the slug
hmm
If you want these routes to be dynamic and they cannot be statically rendered, I guess you have to use nuxt build and do a route rules to define which should be static and which not https://nuxt.com/docs/guide/concepts/rendering#route-rules
Yeah maybe that only works when these pages are linked somewhere (in my case the blog posts are linked on another page)
hmm
I think its a netlify problem
A configuration problem
Not a Nuxt related Issue.
exactly, and my routes have like 300 instances , not avail in the front end
You can configure netlify to not return a 404 by adding this: https://docs.netlify.com/routing/redirects/rewrites-proxies/#history-pushstate-and-single-page-apps
But that's not a solution, since it's still bad for seo when your pages generate only client-side
What did the view-source: show?
I think we have to optimize the Nitro Netlify Preset
HTML Output
it's kind of both, they correlate 😄
For me it only shows an empty html page
<!DOCTYPE html>
<html >
<head><meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1"><link rel="modulepreload" as="script" crossorigin href="/_nuxt/entry.5670447a.js"><link rel="prefetch" as="script" crossorigin href="/_nuxt/error-component.4a691e1d.js"></head>
<body ><div id="__nuxt"></div><script>window.__NUXT__={serverRendered:false,config:{public:{},app:{baseURL:"\u002F",buildAssetsDir:"\u002F_nuxt\u002F",cdnURL:""}},data:{},state:{}}</script><script type="module" src="/_nuxt/entry.5670447a.js" crossorigin></script></body>
</html>
Which is bad for SEO
So it's not only a netlify problem, but also you have empty pages which then just work because they client-side render.
Surely it is, but that's not really the problem.
The 404 does not show up on vercel
okay, then just configure netlify rewrite I guess https://docs.netlify.com/routing/redirects/rewrites-proxies/#history-pushstate-and-single-page-apps
Checkout this @wispy prawn
There is html content
It is a Netlify Problem
Interesting
Creating an Issue on Nitro Repository?
What did the vercel logs tell about the generation of html?
Wait.
wow
Maybe vercel is a bit more intelligent and knows how to render stuff dynamically on the server, therefore not returning 404 and returning content inside view-source
Vercel has a own Nitro Preset
Its building different I think
yes
@gentle kestrel did you use nuxt generate?
but in my case it would not have all the ref numbers to prerender with
The logs says it uses nuxt build. But I can't overwrite it to nuxt generate
hmm
you can in the vercel settings
maybe nuxt build on netlify would work
@foggy flint probably it will work yes
maybe they know this problem
No I think not
@gentle kestrel But why would this save button be disabled?
Because its the same
With the vercel preset it also prerenders the routes
And gives a static output
woohoo, changin to nuxt build has fixed it
Yes, as @wispy prawn said. But then its a problem with Nuxi generate
Okay so I guess let's create an issue at nuxt/nuxt about nuxt generate?
Since it's in experimental state maybe this can be improved
ok so i have now lost my prerendering?
yeah that's the downside of using nuxt build
yes i see
try to use routeRules to improve that https://nuxt.com/docs/guide/concepts/rendering#route-rules
yes ok
But even with that I guess you are not going to be able to enable prerendering
yeah I think so
basically you need some smart config to combine the statig generation and the dynamic, SPA style routes. I have a script that hits the backend ob build to fetch data and build all the urls for the sitemap.
Who of us will raise the Issue?
I dont mind but you guys would probably describe it better
Thanks
Environment Operating System: Linux Node Version: v18.7.0 Nuxt Version: 3.2.2 Nitro Version: 2.2.2 Package Manager: [email protected] Builder: vite User Config: - Runtime Modules: - Build Modules: - Repro...
@foggy flint Daniel commented, and as @wispy prawn said you'll have to link pages, Nuxt only prerenders pages which gets crawled.
You can add you're routes to the nitro.prerender.routes array in your Nuxt Config
Seems fair
So maybe add a function that fetches a list of all the routes from the server before build