The not-found file is used to render UI when the notFound function is thrown within a route segment.
not-found.js components do not accept any props.
By default, not-found is a Server Component. You can mark it as async to fetch and display data
Invoking the notFound() function throws a NEXT_NOT_FOUND error and terminates rendering of the route segment in which it was thrown.
If you need to use Client Component hooks like usePathname to display content based on the path, you must fetch data on the client-side instead.
Imagine we have a product detail page at /products/[id]. If a user inputs an ID that doesn't exist in our database, how would you trigger our custom 404 UI from inside that Server Component?
We have a custom not-found.js file in our root app/ directory, but we want a completely different, simplified 404 page specifically for our /dashboard routes. How would you set up the file structure to achieve this?
We noticed that when a 404 error occurs inside /dashboard/settings, the custom 404 page is rendering inside our complex dashboard sidebar layout. The design team wants the 404 page to be full-screen without the sidebar. How would you refactor the layouts and not-found.js files to fix this?
You're calling notFound() inside a Server Component after a failed fetch. However, you notice the page is crashing with a runtime error instead of showing the not-found.js UI. What are the common reasons this might happen, and how would you debug it?
We are building a multi-tenant application where each tenant has its own branding. When a sub-page is not found, we need the not-found.js page to dynamically fetch and display that specific tenant's theme and logo. How would you architect this, keeping in mind that not-found.js doesn't receive route parameters directly?
We have a static site with thousands of pre-rendered product pages. When a user requests a non-existent product, we want to return a 404. How does Next.js handle the caching and CDN edge-caching of these dynamically triggered 404 responses, and how would you optimize this to prevent server overload?
We are migrating a massive legacy Next.js Pages Router application to the App Router. In the old system, we had a highly customized pages/404.js that integrated with our global middleware for geo-routing and third-party analytics tracking. How would you design the migration path for this 404 behavior to the App Router, ensuring we don't lose analytics accuracy or break localized routing?
In a large monorepo with multiple federated teams contributing to different route groups, we need to enforce a consistent global error and 404 handling strategy. How would you design a reusable routing/error boundary architecture using not-found.js and error.js that teams can easily adopt without duplicating boilerplate or breaking global telemetry?