Next.js Discord

Discord Forum

One-word post slug loads, multi-word post slug 404

Unanswered
Mugger Crocodile posted this in #help-forum
Open in Discord
Mugger CrocodileOP
Hey all,

TLDR: one-word post slug with the id appended separated by hyphen (i.e. "title-aaaaaaaa") loads correctly, multi-word post slug with the id appended separated by hyphen (i.e. "heres-a-longer-title-aaaaaaaa") brings up 404 page.

I'm using Next.js14, Sanity CMS and deploying on Vercel.

I've a route structure that looks something like this: website.com/[location]/[category]/[post]

The post slug is set up that if the category is "updates", the first part of the post id (i.e. "aaaaaaaa" of post id "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee") is appended to the end of the post slug (i.e. the [post] route segment might look like "post-slug-aaaaaaaa").

The GROQ query is returning everything as expected (I'd love to dump the query here but there's a word limit, so I'd share it if anyone wishes to help). All the console.logs are returning the correct data and if i used a one-worded slug with the id appended (i.e. "title-aaaaaaaa").

But when the slug gets any longer (i.e. more than one hyphen like this "heres-a-longer-title-aaaaaaaa"), i'm directed to 404, both on production and local environment. Strange thing is when i inspect the <head>, the meta data shows the meta data of the correct post (the generateMetadata function is sharing the same data from the same GROQ query function as the Post function, which renders the post page).

Now I also have other categories with posts with multi-word slugs, but the slugs are used as-is, no id appended to them, and they load correctly.

I've already tried console.logging as much as I can and I'm getting the expected data. What confuses me the most is when I change the multi-word slug to a single word, the page loads!

Anyone encountered this before?

0 Replies