Provide a way to pass custom data to the 404 page when notFound: true, or return specific page #28953
Replies: 3 comments 2 replies
-
Thanks for posting this. I also very much need to return custom props to 404 pages. One alternative for |
Beta Was this translation helpful? Give feedback.
-
I want to give a heavy 👍 to this request and expand upon it to support more nuanced responses than simply
or
we also need a pattern for handling:
allowing a "successful" response from |
Beta Was this translation helpful? Give feedback.
-
The more I look at this code the more I feel constrained by It would be far more useful for methods like What I am looking for is the ability to raise or return different types of errors to more explicitly express our error landscape, and to be able to pass more context from the site of those errors to our error page so that:
|
Beta Was this translation helpful? Give feedback.
-
Describe the feature you'd like to request
When using
getStaticProps
, it is currently possible to return either props and a page, or notFound: trueExample
Currently it is not supported passing props down when returning
or specifying a page you want to return like
Passing props down here is very useful for showing different 404 content for different pages.
Example:
requested user profile not found
requested post does not exist anymore
requested product does not exist
and so on
For all possible different not found types, we would like to show beautiful nice unique 404 pages for a great customer experience, and not just a generic "404 - page not found".
Describe the solution you'd like
Solution 1:
Change the possible response of GetStaticPropsResult from
to (only last row changed, allow passing props to notFound)
Then in 404.ts we can use the prop
if (props.type === 'user') {
return
Requested user is not found
}
// and so on for different types
Solution 2
If our fetch logic notices that a particular item does not exist, api returns 404, allow to return a custom "view" page (without using the redirect and increase the overhead).
example:
pages/posts/[id].tsx
Describe alternatives you've considered
I have considered some hacky solution to check in the 404.tsx page the current url, then use the client router to determine the current page, then show a cusomised message.
I would prefer to have implemented in next the suggested solution 2, with full power and flexibility of returning a specific page for a given 404 error, based on the data type (post, user, song, product, etc)
Beta Was this translation helpful? Give feedback.
All reactions