Why am I getting a 404 with dynamic params on a generated page?
Answered
Himalayan posted this in #help-forum
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
HimalayanOP
Why am I getting a 404 when visiting
The page works when
/posts/general/post-1
app/posts/[category]/[slug]/page.tsx
export const dynamicParams = false;
export async function generateStaticParams() {
const { data } = await getClient().query({
query: PostSlugsDocument,
});
const { items } = data?.postSlugs || {};
if (!items) {
return [];
}
return items?.map(post => ({
category: post?.category?.slug,
slug: post?.slug,
}));
}
The page works when
dynamicParams
is true
, but 404
's when false
.18 Replies
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
HimalayanOP
Could it be that the page is only ever rendering dynamically?
![Avatar](https://cdn.discordapp.com/avatars/743561772069421169/3c5d689eee4459a24fc420063411c016.webp?size=256)
Ray
yes that's exactly what dynamicParams does
true (default): Dynamic segments not included in generateStaticParams are generated on demand.
false: Dynamic segments not included in generateStaticParams will return a 404.
![Avatar](https://cdn.discordapp.com/avatars/743561772069421169/3c5d689eee4459a24fc420063411c016.webp?size=256)
Ray
which mean
post-1
not get generated at build timeAnswer
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
HimalayanOP
But the segment is included in
post-1 should have been generated
generateStaticParams
, post-1 should have been generated
![Avatar](https://cdn.discordapp.com/avatars/743561772069421169/3c5d689eee4459a24fc420063411c016.webp?size=256)
Ray
export async function generateStaticParams() {
const { data } = await getClient().query({
query: PostSlugsDocument,
});
const { items } = data?.postSlugs || {};
console.log(items) <-- see if you get the items
if (!items) {
return [];
}
return items?.map(post => ({
category: post?.category?.slug,
slug: post?.slug,
}));
}
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
HimalayanOP
Yeah logs correctly
![Avatar](https://cdn.discordapp.com/avatars/743561772069421169/3c5d689eee4459a24fc420063411c016.webp?size=256)
Ray
could you show the log?
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
HimalayanOP
(post-1) is an example name by the way
![Avatar](https://cdn.discordapp.com/avatars/743561772069421169/3c5d689eee4459a24fc420063411c016.webp?size=256)
Ray
no post-1 here
and no general
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
HimalayanOP
You may be on to something, will take a closer look thank you
As a matter of fact none of those posts or categories should exist, was all updated.
So perhaps a caching issue
So perhaps a caching issue
![Avatar](https://cdn.discordapp.com/avatars/743561772069421169/3c5d689eee4459a24fc420063411c016.webp?size=256)
Ray
what is getClient()?
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
HimalayanOP
Yeah was cache, deleted .next and it's refreshed
export const { getClient } = registerApolloClient(() => {
return new NextSSRApolloClient({
cache: new NextSSRInMemoryCache(),
link: new HttpLink({
uri: `${CONTENTFUL_BASE_URL}${CONTENTFUL_SPACE_ID}`,
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${CONTENTFUL_DELIVERY_TOKEN}`,
},
}),
});
});
![Avatar](https://cdn.discordapp.com/avatars/743561772069421169/3c5d689eee4459a24fc420063411c016.webp?size=256)
Ray
const { data } = await getClient().query({
query: PostSlugsDocument,
context: {
fetchOptions: {
cache:'no-store'
},
},
});
I think you can disable the data cache like this since you are building static page
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
HimalayanOP
Good idea, thank you and thank you for your help