Steps to Implement not-found File Convention in Next JS

Step 1: To create your app, run the following npx command in your terminal to start the creation process:

 npx create-next-app@latest

Step 2: Provide the necessary details to create your app as shown in the image below.

Providing the necessary details to create-next-app

Step 3: Your project would be created by now. Go inside your project directory and start the development server through the following command:

npm run dev

Next JS File Conventions: not-found.js

NextJS is a React framework that provides several features to help you build fast and scalable web applications. One of these features is not-found.js which allows you to create a “Not Found” UI for your application which is rendered whenever the “notFound” function is thrown within a route segment.

Similar Reads

Next JS Not Found Handling and Access Control:

In NextJS, you can use the “notFound” function to hide certain pages from certain users (for example, you might want to hide the admin page from a normal user). In those cases, the UI shown to the user can be defined inside the “not-found.js” file created inside that route segment. Also, Next.js will return a 200 HTTP status code for streamed responses, and a 404 HTTP status code for non-streamed responses....

Props:

not-found.js components do not accept any props. Components defined in “not-found.js” cannot receive or utilize any external data passed as props. This restriction limits their ability to dynamically adapt or display content based on external input, making them static in nature....

Data Fetching:

By default, “not-found.js” functions as a Server Component. To enable data fetching and display based on path using Client Component hooks like usePathname, mark it as async. However, if client-side hooks are essential, fetch data on the client-side instead....

Steps to Implement not-found File Convention in Next JS:

Step 1: To create your app, run the following npx command in your terminal to start the creation process:...

Project Structure:

Project Structure...

Contact Us