Skip to content
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

Docs: unclear documentation about layout.js #60617

Closed
SmartMointy opened this issue Jan 14, 2024 · 4 comments
Closed

Docs: unclear documentation about layout.js #60617

SmartMointy opened this issue Jan 14, 2024 · 4 comments

Comments

@SmartMointy
Copy link

What is the improvement or update you wish to see?

Remove this line from layout.js docs under Root Layouts

  • The app directory must include a root app/layout.js.

Or provide a workaround on how to set <html lang={params.lang} inside a app/[lang]/layout.js

Is there any context that might help us understand?

In the docs about layouts it says that:

  • "The app directory must include a root app/layout.js"
  • "The root layout must define <html> and <body> tags".

Using next-intl or any similar i18n routing leads all pages being inside app/[lang] or app/[locale].

So if we have to put the root layout into the app folder we can't set <html lang={params.lang}> since we can only access the locale inside the app/[lang]/layout.js file.

Also having no app/layout.js works without any error or warning.

Does the docs page already exist? Please link to it.

https://nextjs.org/docs/app/api-reference/file-conventions/layout

@SmartMointy SmartMointy added the Documentation Related to Next.js' official documentation. label Jan 14, 2024
@JasonA-work
Copy link

Just ran in this problem when trying to implement i18n on my site too.

Additionally, this introduces a problem with the not-found.js. When we don't have app/layout.tsx, we get this error:

not-found.tsx doesn't have a root layout. To fix this error, make sure every page has a root layout.

And when you do put the root layout in the app dir, we get the problem where we need an html tag in app/[locale]/layout.tsx too - and that's where we need to have language parameters as an attribute to the html tag like mentioned above.

@SmartMointy
Copy link
Author

SmartMointy commented Jan 27, 2024

@JasonA-work I am on version "14.0.4" and get the same error trying to use a custom 404 page.

Another issue for me is that you can't have a navbar and footer on the 404 page, since they need i18n and mostlikly are used inside the app/[lang]/layout.tsx layout, which is not wrapped by the app/not-found.tsx... Therefore having a generic Link to the homepage on the 404 page is the only option atm.

@JasonA-work
Copy link

@SmartMointy I'm on 14.1. Perhaps that's why.

I finally found a solution that works from here:

https://next-intl-docs.vercel.app/docs/environments/error-files

Hope it becomes useful to you!

To the Next JS team: @leerob Is it possible to include the information in your docs under the i18n topic? This is issue should be a common one and the solution to it is not straightforward. So having this in the docs will be very helpful.

Thank you!

@samcx samcx removed the Documentation Related to Next.js' official documentation. label Jan 22, 2025
@samcx
Copy link
Member

samcx commented Feb 25, 2025

Also having no app/layout.js works without any error or warning.

@SmartMointy I don't think this is true now—I am seeing an error.

Closing this since this is indeed required and and an error is showing.

@samcx samcx closed this as completed Feb 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants