Hi,
I'm developing my project with Next.js and I found that querying document with old uid led to 404 page is related to fallback
value in getStaticPaths
.
Now I can access document with old uid again after changing fallback value from false
to true
.
But now I encountered another difficulty is I can't handle non-existent uid case.
Originally it will return 404 page if the uid is not in the paths returned by getStaticPaths
with fallback set to false
. I will get error message: "no documents were returned" in getStaticProps
function with the query below.
const doc = await client.getByUID('post', params.uid, {
lang: language,
}) || {}; // Get no documents returned error if the entered uid is not existed
FYI: I was trying to implement a 301 redirect practice with custom hook according to the this discussion. Not sure if it's the best practice since the custom hook in the example is called conditionally.