Can a Page.tsx return nothing
Answered
Serengeti posted this in #help-forum
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} />;
}
}
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?
3 Replies
@Serengeti 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} />;
}
}
You can return null yes. That said why don’t you use notFound() when the page is… not found?
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;