How can I return 404 error if there is no data? #2262
Answered
by
imadatyatalah
imadatyatalah
asked this question in
Q&A
-
Something similar to this: export async function getStaticProps(context) {
const res = await fetch(`https://.../data`)
const data = await res.json()
if (!data) {
return {
notFound: true,
}
}
return {
props: { data }, // will be passed to the page component as props
}
} My code: export const getStaticPaths = async () => {
return { paths: [], fallback: true };
};
export const getStaticProps = async ({ params }) => {
const queryClient = new QueryClient();
await queryClient.prefetchQuery(["posts", params.user], () =>
fetcher(`http://localhost:3000/api/user/${params.user}`)
);
return {
props: { dehydratedState: dehydrate(queryClient) },
revalidate: 1,
};
}; |
Beta Was this translation helpful? Give feedback.
Answered by
imadatyatalah
May 11, 2021
Replies: 1 comment
-
I've fixed the issue via fetchQuery(), Thanks #1494 |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
imadatyatalah
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've fixed the issue via fetchQuery(), Thanks #1494