Next.js Discord

Discord Forum

Next 13 metadata for not-found page

Unanswered
White-horned horntail posted this in #help-forum
Open in Discord
White-horned horntailOP
Cannot overwrite a global <title> metadata for not-found page. I tried to paste <title> inside page itself but in this case it just puts both global title and the one is set in not-found page. export const metadata and export const generateMetadata doesn't work as well

38 Replies

White-horned horntailOP
@Ray server
but can be client, doesnt matter for me
export const metadata should work then
but it didn't change the title for you?
White-horned horntailOP
yes, it just still keeps the one set in global metadata for layout.tsx
I tried both

export const metadata = {
title: '404 not found page',
};

export const metadata = {
title: { absolute: '404 not found page' },
};
White-horned horntailOP
yup
White-horned horntailOP
exactly
and here is metadata for app/layout.tsx

title: {
default: title,
template: '%s | My Site name',
},
then it should work, have you tried remove .next folder and restart the server?
White-horned horntailOP
I tried everything, maybe the problem in the version of next js i'm using (13.4.19). The metadata works for all pages I have except this one, I found a thread on github with the same problem but their solution doesn't work for me
let me try it on 13.4.19 real quick
it works for me on 13.4.19
White-horned horntailOP
did you set a global metadata for title as well?
yes
export const metadata: Metadata = {
  title: {
    default: "Create Next App",
    template: "%s | My Site name",
  },
  description: "Generated by create next app",
};
and
export const metadata: Metadata = {
  title: "404",
};
White-horned horntailOP
hmmm, could you also try to hit error page through notFound() from existing page?
the title doesn't set if hit notFound()
could you try access some random url which is not exist?
btw look like you need to upgrade to get it fix
White-horned horntailOP
Actually it doesn't work even with a random page for me, it just keeps title which was set in title.default
upgrade to which version?
is there a reason you using old version instead of latest one?
White-horned horntailOP
I think I found a way to fix it, I just added metadata to [...not-found]/page.tsx and it works
lol
White-horned horntailOP
maybe not a best solution but at least it works haha
but thank you!
np
White-horned horntailOP
hell, it still doesn't work by hitting notFound(), don't you know in which version it was fixed?
try creating a new project and test lol