You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/01-app/03-api-reference/03-file-conventions/not-found.mdx
+74-6Lines changed: 74 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -44,7 +44,11 @@ export default function NotFound() {
44
44
45
45
The `global-not-found.js` file lets you define a 404 page for your entire application. Unlike `not-found.js`, which works at the route level, this is used when a requested URL doesn't match any route at all. Next.js **skips rendering** and directly returns this global page.
46
46
47
-
This is useful when you can't build a 404 page using a combination of `layout.js` and `not-found.js`. This can happen in two cases:
47
+
The `global-not-found.js` file bypasses your app's normal rendering, which means you'll need to import any global styles, fonts, or other dependencies that your 404 page requires.
48
+
49
+
> **Good to know**: A smaller version of your global styles, and a simpler font family could improve performance of this page.
50
+
51
+
`global-not-found.js` is useful when you can't build a 404 page using a combination of `layout.js` and `not-found.js`. This can happen in two cases:
48
52
49
53
- Your app has multiple root layouts (e.g. `app/(admin)/layout.tsx` and `app/(shop)/layout.tsx`), so there's no single layout to compose a global 404 from.
50
54
- Your root layout is defined using top-level dynamic segments (e.g. `app/[country]/layout.tsx`), which makes composing a consistent 404 page harder.
@@ -66,9 +70,45 @@ export default nextConfig
66
70
Then, create a file in the root of the `app` directory: `app/global-not-found.js`:
description:'The page you are looking for does not exist.',
107
+
}
108
+
69
109
exportdefaultfunctionGlobalNotFound() {
70
110
return (
71
-
<html>
111
+
<html lang="en" className={inter.className}>
72
112
<body>
73
113
<h1>404- Page Not Found</h1>
74
114
<p>This page does not exist.</p>
@@ -140,18 +180,46 @@ If you need to use Client Component hooks like `usePathname` to display content
140
180
141
181
For `global-not-found.js`, you can export a `metadata` object or a [`generateMetadata`](/docs/app/api-reference/functions/generate-metadata) function to customize the `<title>`, `<meta>`, and other head tags for your 404 page:
142
182
183
+
> **Good to know**: Next.js automatically injects `<meta name="robots" content="noindex" />` for pages that return a 404 status code, including `global-not-found.js` pages.
0 commit comments