-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to have global layout - custom "not-found" 404 page and global Metadata #6695
Comments
@todor0v Why can't you define global metadata in |
@bryanjhickey I could if I have the other pages in |
I also found another weird behavior that I cannot debug so far. |
I believe that I found a better solution So to summarize, the solutions are as follows:
export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return children;
} Then create an
@jacobsfletch Ok scratch that. If you do this solution for a 404 page, everything that is an inner path of an existing page, but results in 404 (such as |
@todor0v first of all, thank you for the details here. Great to see and very helpful. I went ahead and took a quick pass at #6511 just now and found a temporary workaround. Check out my comment here for details. Let me address a few of your points directly:
When you say "global" I assume you mean throughout every page within your own application, i.e. not including the admin panel. So for example, you can control metadata for your "home" page and your "about" page from the same location. This should already work as-is. In your application you should have a Here's the setup:
In import { notFound } from 'next/navigation';
export default function NotFoundDummy() {
notFound();
} In export const metadata = {
title: 'This is global metadata for your app',
}
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<body>{children}</body>
</html>
)
} |
@jacobsfletch Thank you so much for the help! This solution works for me and I can have a global 404 page without the workaround with returning different code structure for the panel and the global layout. I only have one problem with this approach that I discovered. If you go to |
This issue has been automatically locked. |
Link to reproduction
No response
Payload Version
3.0.0-beta.43
Node Version
20.13.1
Next.js Version
15.0.0-rc.0
Describe the Bug
@jacobsfletch This is related to #6511, however I believe that it is about more than just 404 pages, so I am creating a new issue. Let me know if you do not approve and I will comment there instead.
I have three main problems that I cannot solve with the current
layout.tsx
logic:layout.tsx
First I read the blog post on the beta install and as I understood, if I have
layout.tsx
file inside ofapp/(app)
, that should work globally (I should be able to have the samemetadata
for all pages for example (and then have individual ones if I want to). The more I read through the Demo code, however, the more I don't see how would this be possible. The layout file inapp/(app)
is not a global layout file. Which means that I cannot use it for meta, or 404. This has the additional problem that every time I create a new page, Next.js generates alayout.tsx
automatically for that path. I end up with multiple layout files that are essentially the same thing, because the main one cannot be used.At the same time I cannot just create a
layout.tsx
directly inside ofapp
. This clashes with the Payload/admin
page. This is understandable, but as of now I cannot find a good way to solve my problems. What I was able to do so far is this:src/app/layout.tsx:
Ideally Next.js should provide a way for me to check the
pathname
on the server, however as per this issue, it currently does not. I had to use third party solution to reliably get thepathname
and based on that either return the children directly (thus not affecting the admin panel) or the page (thus being able to have a custom layout.Would you please advise me if there is or there will be a better way to do this in the future?
Thank you!
cc: @jmikrut since you assigned the original issue
Reproduction Steps
npx create-payload-app@beta
layout.tsx
insideapp/(app)
as advisedAdapters and Plugins
db-mongodb, babel-plugin-react-compiler
The text was updated successfully, but these errors were encountered: