Next.js Discord

Discord Forum

Weird URL behaviour after generating staticProps

Unanswered
Spectacled bear posted this in #help-forum
Open in Discord
Spectacled bearOP
Hi guys,

I followed this tutorial: https://nextjs.org/learn-pages-router/basics/dynamic-routes/implement-getstaticprops

And essentially it works great, I rewrote some code of it to parse HTML instead of markdown, and added some extra fields to 'gray-matter' to provide more information on the templates. Nothing too crazy. The URLs also work fine, for example /posts/blog1 and /posts/blog2

Here is where a weird difference comes in: if I check /posts/posts/posts/blog1, or /posts/posts/blog2 when using 'npm run dev', this correctly sends me to the 404 page.
But after building using 'npm run build', this redirects me to the home page, while maintaining the URL structure, thus leading to duplicate URLs and google is not very happy about it.

Another issue is, that going to /posts/[id] works fine on the development environment, but gives a 500 internal server error on production. I also get a minified react error, which I am not able to read.

What should I do, or look to fix this inconsistency?
Thanks!

2 Replies

Spectacled bearOP
The error is: https://react.dev/errors/418?args[]=
which is quite interesting considering this isn't happening on dev
Spectacled bearOP
after some more digging it appears to be caused by Nginx, any good tutorial how to host a static site?