Next.js Discord

Discord Forum

Can a Page.tsx return nothing

Answered
Serengeti posted this in #help-forum
Open in Discord
SerengetiOP
I have a dynamic path where i only want to return the page if the param matches the pages i have is this vaild?

export default function Page({ params }: { params: DynamicPageProps }) {
const page = pages.find(({ slug }) => params.pageName === slug);

if (page) {
const { copy, filters, data } = page;
return <AttributePage filterTopics={filters} heading={copy.heading} subHeading={copy.subHeading} cardData={data} />;
}
}
Answered by joulev
You can return null yes. That said why don’t you use notFound() when the page is… not found?
View full answer

3 Replies

Answer
SerengetiOP
interesting didn't know about that function however the route returns not found without it anyway.
ah that's becuase i'm setting export const dynamicParams = false;