Next.js Discord

Discord Forum

Dynamic slug data fetching

Answered
American black bear posted this in #help-forum
Open in Discord
Avatar
American black bearOP
Hello guys,

I am trying to build a web app and i've got everyhing connected with a headless CMS, which means that i get all the data from API's and i don't know any static information.

What i am trying to build now is a news page, but because the client can choose to name the news whatever they want, i cannot set a folder like [news] or whatever.

I am trying to work with dynamic routes, and i am therefor using the [...slug] method that i found on the docs. But for some reason i get a 404 on my live website, but on my localhost everyhing seems to work fine.

For now i have the following strucuture:
app/[...slug]/page.tsx

And when i visit localhost:3000/news/news-title-1 i get no error on my localhost, but when i visit my vercel preview, i get a 404 when i visit: vercel.app/news/news-title-1

What am i doing wrong here? The /news/ is the page that the client creates in the CMS, the slug after that is the name of the news item and from there on i would fetch data based on the last part of the slug.
Answered by American black bear
Ok i found the solution lol, i also had a older [slug] file and apperently that doesnt work together.
View full answer

5 Replies

Avatar
Pectoral Sandpiper
Missing app folder maybe? app/news/title1/title2
Avatar
American black bearOP
The app folder should not be in the url?
Avatar
it shouldn't...
Avatar
American black bearOP
Ok i found the solution lol, i also had a older [slug] file and apperently that doesnt work together.
Answer
Avatar
nice that you fixed it 🙂