From the course: Learning Next.js

Unlock this course with a free trial

Join today to access over 25,300 courses taught by industry experts.

Solution: Handling 404 errors with notFound functions

Solution: Handling 404 errors with notFound functions

From the course: Learning Next.js

Solution: Handling 404 errors with notFound functions

Okay. So for the next challenge. So here the goal is to display a Replacement UI in the case that one resource is not found. And we're going to use this notFound function. So let's go ahead and create also for our example a 'not-found' file right here we're going to use the same example. And we're going to go find this specific route which is a dynamic route. Here you see that we only have one page. So which is the actual page to display a blog post? But the thing is that we need to also handle any form for error in the case that one post is not available / does not exist. So for that, we're going to do just like the example. We're going to add, create a 'not-found.tsx' and use the same layout. We're going to copy this code snippet, I'm gonna paste here and just replace with our own information. So here in our case, we're going to say and read "Could not find the requested blog post" and allow to go back to the list. The full list of blog posts, like this. All right, so this is all…

Contents