#dynamic routes working but have 404 status code

1 messages · Page 1 of 1 (latest)

foggy flint
#

Hi all!
So I have an SEO problem here as a result of this . Even though the pages are rendering perfectly the status is 404. If anyone has insight would be very gratefull

wispy prawn
#

Hi, does this happen on devserver? locally build preview? or deployed build?

foggy flint
#

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

gentle kestrel
#

Does this happen on every page? @foggy flint

foggy flint
#

every instance of this '/packages/[ref]/[slug] route

gentle kestrel
#

Do you have any custom Nitro Configuration?

foggy flint
#

no

gentle kestrel
#

And this does not happen on Dev Mode, right?

foggy flint
#

right

gentle kestrel
#

Can you show me npx nuxi info output & your nuxt.config?

foggy flint
#

config:

gentle kestrel
#

okay, delete the message. Just leaked your Directus Token.

foggy flint
#

```- Operating System: Darwin

foggy flint
gentle kestrel
#

Does one of the modules can cause the error?

foggy flint
#

hmm well i just saw i can get rid of the sitemap one. trying that

gentle kestrel
#

Are you prerendering the pages?

foggy flint
#

yes , ssr is default value so true

gentle kestrel
#

And you are deploying with nuxi generate?

foggy flint
#

yes

gentle kestrel
#

Okay, can you show me your Dynamic Page?

foggy flint
gentle kestrel
#

Just for debugging, Can you remove line 71 to 75

#

And try it with that

foggy flint
#

yes i actuaky have tried that

#

same behaviour

gentle kestrel
#

Hmm

#

Anything else where you throw a 404 error?

wispy prawn
#

Does it happen on other routes too? Or only on this?

foggy flint
#

no, only this

#

the only other 404 is any invalid route, which returns my error.vue component in the root directory

gentle kestrel
#

Try to remove it

#

And show us your error.vue

wispy prawn
#

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?

gentle kestrel
#

Maybe you try to deploy on an other service?

foggy flint
#

ok with npx nuxi generate?

gentle kestrel
#

Yes

wispy prawn
#

Do you have another dynamic route in your project? Or is this the only one

foggy flint
#

the only one

#

oh actually i have blogs

#

good point

wispy prawn
#

check if thats the same there

#

and check the build logs, it should exactly list which pages are being generated

gentle kestrel
#

Okay maybe a netlify problem with the dynamic routes.

#

Did you tested it locally?

foggy flint
#

building now

#

interesting

#

no package html , or blogs html

gentle kestrel
#

How do you mean that?

#

They doesn't exist?

#

Can you show us the output of nuxi generate

foggy flint
#

no. folders for all stic pages but not the dynamic ones

gentle kestrel
#

If you try to test it local, using serve or something else. Do you also get the 404?

foggy flint
#

no i dont

gentle kestrel
#

How do you start it locally?

foggy flint
#

yarn dev

gentle kestrel
#

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?

foggy flint
#

hmm no sounds good!

gentle kestrel
#

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
foggy flint
#

ok

#

you guys rock btw

#

ok have pushed the nitro preset in the meantime

gentle kestrel
#

Same problem

foggy flint
#

ah you checked?

gentle kestrel
#

Yes

foggy flint
#

serving static output, no 404!

gentle kestrel
#

okay, its a deployment problem.

#

I think the nitro netlify preset needs more specific configuration for dynamic routes.

#

Let me check something.

foggy flint
#

ok

gentle kestrel
#

Can you show me your netlify configuration, so the configured commands?

foggy flint
gentle kestrel
#

How does Netlify start it?

foggy flint
#

oh after the build ? hmm

gentle kestrel
#

Yes

#

Is there a 200.html file in your static output? @foggy flint

foggy flint
#

yes

gentle kestrel
#

And a 404.html?

foggy flint
#

yup

gentle kestrel
#

okay

foggy flint
#

not sure how netlify starts it. Maybe i should try vercel

gentle kestrel
#

You can try that, and it will certainly work. But still, it's not right.

foggy flint
#

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

gentle kestrel
#

Maybe you make them ClientOnly if this is not a problem

#

But in every case, this problem should be documented.

foggy flint
#

I know right

#

but let me try that, just wrap the page in <ClientOnly>?

gentle kestrel
#

Yes

#

I will create an example on GitHub and try to find a solution for this issue.

foggy flint
#

thanks so much

gentle kestrel
#

No Problem

#

Let me know if the ClientOnly helps

wispy prawn
#

@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.

gentle kestrel
#

@foggy flint How do you named the slug file?

foggy flint
gentle kestrel
#

Try to name it just: [slug].vue

foggy flint
#

it used to be like that

wispy prawn
#

Any reasons why there is double [[ref]]?

foggy flint
#

the docs say that makes is optional

#

was trying it out

wispy prawn
#

Okay but optional + something dynamic inside idk if that works, maybe that's the reason

foggy flint
#

ok going back to simple naming now

gentle kestrel
#

I will try to reproduce this error with netlify

gentle kestrel
#

When he trys to serve it locally it works

wispy prawn
#

I know

gentle kestrel
#

I think its a problem with the Netlify configuration

wispy prawn
#

but the generator may not catch it as something to generate

gentle kestrel
#

Hmm

wispy prawn
#

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

foggy flint
#

yes right, but how are yours getting generated. the slug title are coming from links in the site right

gentle kestrel
#

I have the same problem

#

I can reproduce it

#

With a normal dynamic page @wispy prawn

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.

foggy flint
#

ok

gentle kestrel
foggy flint
#

hmm

wispy prawn
wispy prawn
foggy flint
#

hmm

gentle kestrel
#

I think its a netlify problem

#

A configuration problem

#

Not a Nuxt related Issue.

foggy flint
wispy prawn
#

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?

gentle kestrel
#

I think we have to optimize the Nitro Netlify Preset

gentle kestrel
wispy prawn
foggy flint
gentle kestrel
#

I will deploy this example on vercel.

wispy prawn
#

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.

gentle kestrel
#

The 404 does not show up on vercel

wispy prawn
gentle kestrel
#

There is html content

#

It is a Netlify Problem

wispy prawn
gentle kestrel
#

Creating an Issue on Nitro Repository?

wispy prawn
#

What did the vercel logs tell about the generation of html?

gentle kestrel
#

Wait.

foggy flint
#

wow

wispy prawn
#

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

gentle kestrel
#

Its building different I think

foggy flint
#

yes

gentle kestrel
#

okay no

#

wait

wispy prawn
#

@gentle kestrel did you use nuxt generate?

foggy flint
#

but in my case it would not have all the ref numbers to prerender with

gentle kestrel
#

The logs says it uses nuxt build. But I can't overwrite it to nuxt generate

foggy flint
#

hmm

wispy prawn
gentle kestrel
#

No

#

I cant change it there

foggy flint
#

maybe nuxt build on netlify would work

gentle kestrel
#

It thinks its the same

#

Wait

wispy prawn
#

@foggy flint probably it will work yes

gentle kestrel
#

Can't use the Save button

#

when I try overwrite

foggy flint
#

maybe they know this problem

wispy prawn
#

no way, that's a vercel bug

#

so many bugs today hahah

gentle kestrel
wispy prawn
#

@gentle kestrel But why would this save button be disabled?

gentle kestrel
#

Because its the same

#

With the vercel preset it also prerenders the routes

#

And gives a static output

wispy prawn
#

Can you send in the full build log?

#

To see what it does exactly

gentle kestrel
foggy flint
#

woohoo, changin to nuxt build has fixed it

gentle kestrel
#

Yes, as @wispy prawn said. But then its a problem with Nuxi generate

foggy flint
#

you guys are super ninjas and Jedi masters

#

yes

wispy prawn
#

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

foggy flint
#

ok so i have now lost my prerendering?

wispy prawn
foggy flint
#

yes i see

wispy prawn
foggy flint
#

yes ok

wispy prawn
#

But even with that I guess you are not going to be able to enable prerendering

foggy flint
#

yes

#

well worth raising an issue right?

wispy prawn
#

yeah I think so

foggy flint
#

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.

gentle kestrel
#

Who of us will raise the Issue?

foggy flint
#

I dont mind but you guys would probably describe it better

gentle kestrel
#

I will create an issue and mention you guys

#

@foggy flint Your Github @?

foggy flint
#

ok awesome

#

sharkfin009

gentle kestrel
#

Thanks

#

@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

wispy prawn
#

Seems fair

#

So maybe add a function that fetches a list of all the routes from the server before build

foggy flint
#

awesome, will work on that

#

why no prob on vercel

#

oh because no prerender, sorry

foggy flint