Next.js removes meta title on 404 page. #81919
Replies: 2 comments
-
Hi! 👋 I ran into a similar issue with custom not-found.jsx pages and metadata in Next.js App Router. It sounds like: You’re using a custom NotFound component. You set a title in metadata, but it briefly appears, then disappears after render. This seems to be a known limitation or bug in how Next.js handles metadata on error and not-found routes. 🛠️ Possible Solutions / Workarounds: tsx const NotFound = (props) => ( 404 – Page Not Found{/* Your not found content */} </> ); export default NotFound; ✅ 2. Upgrade Next.js Version Run: bash ✅ 3. Use generateMetadata() for More Control tsx const Page = async () => { export default Page; |
Beta Was this translation helpful? Give feedback.
-
Root Cause
SolutionsOption 1: Move Data Fetching// src/app/not-found.jsx
export const metadata = {
title: 'Page Not Found',
};
// Fetch data HERE (not inside Page component)
const siteData = await fetchRoute(ApiRoutes.GLOBALS);
const Page = () => {
return <NotFound {...siteData.notFound} />;
};
export default Page; |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
When I try to open a page that doesn't exist, I redirected to a 404 page. It works, I see my NotFound component.
But. At first, I see the meta title 'Page Not Found' that I set for it. But after 1 second, it disappears, Next.js removes it from the DOM. In the end, the browser tab shows the URL where the title should be.
Additional information
I have custom Not Found page (
src/app/not-found.jsx
):next info
output:Beta Was this translation helpful? Give feedback.
All reactions