-
Notifications
You must be signed in to change notification settings - Fork 27.3k
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
Global not-found not available in multiple root layouts #55191
Comments
This is the Solution We Just Need to Restructure Our Code.
After Restructuring The Folders and Files Look Like this.
Here are 2 layout.tsx Both Containing Root Layout For Example layout.tsx in (default_site)/ contains the global AdSense Code with Google Analytics. But Error Page Like 404 Page only Contains the google analytics and there is no adsense code there at all. As Per NextJS Docs We Can Have Multiple RootLayout for Multiple Parts of our site like sub applications by this way. Here The [...not_found]/page.tsx Only Created Once in error layout. It's Content Are Like Given Below. import {notFound} from "next/navigation"
export default function NotFoundCatchAll() {
notFound()
} Hope this Solves Your Issue @devjiwonchoi |
@shriekdj Thanks for the suggestion! I believe that it is not the developers' responsibility to configure inefficient structure (such as creating another route group for catch-all in your example) which could be resolved if support this issue or better as a default feature. |
I just ran into this. I love routing by convention, but when those conventions don't work - it sucks. Please fix this nextjs team! |
I also ran into the same problem. I'm glad that I found a solution, but the documentation says that it works when there is no global matching file path. It's unintuitive that it doesn't work with https://nextjs.org/docs/app/api-reference/file-conventions/not-found I would like you to either fix it or write a solution for this in the documentation. |
I have the same issue with my folder structure. Unfortunately you soulution @shriekdj doesn't satisfies my requirements as I want the 404 be displayed within my group root which has all authentication and navigation setup already. For second layout which is public and doesn't contain any auth etc. it should handle 404 with its own layout which doesn't seem currently possible.. |
@stychu my structure have two grouping layout both have where the |
Hi @shriekdj , I misunderstood your answer at first. After looking closely again and adding the
|
I am still Facing this. The Only workaround is catch-all routes but I wouldn't say I like this structure as it kills the purpose of group routing. |
happy to help @stychu |
@ugb-access what structure you have currently? |
Note that the workaround given by shriekdj does not work for static exports. Navigating to a route that does not exist (here
It would be great to get input from the NextJS team on this, this is an import feature that is currently missing from multiple root layout and is not documented |
Hi everyone, it seems like we could resolve it via setting the global not-found for each groups: .
└── app/
├── (main)/
│ ├── layout.tsx
│ ├── not-found.tsx
│ └── page.tsx
└── (sub)/
├── sub/
│ └── page.tsx
├── layout.tsx
└── not-found.tsx EDIT: My bad, I forgot the context. I'll try to bring up this issue. |
├── (cart) This is my current structure. |
## Why? For multi-root layouts (route groups on the root with their root layouts, no layout file on the root), it is not possible to use global `not-found` since the `layout` is missing on the root. ```sh . └── app/ ├── (main)/ │ └── layout.js ├── (sub)/ │ └── layout.js └── not-found.js --> ERR: missing layout ``` Current Behavior: ```sh not-found.js doesn't have a root layout. To fix this error, make sure every page has a root layout. ``` ## What? Let multi-root layouts also benefit from the global `not-found`. ## How? Wrap root `not-found` with default layout if root layout does not exist. Although this solution is not `multi-root` specific, it won't produce critical issues since a root `layout` is required for other cases. Fixes #55191 #54980 #59180
why reopened the issue @shuding |
Unfortunately, I also encountered this problem.
However, I found a similar solution in #50034.
But I don't think this is a good method; at least it can only catch not-found after the [language] dynamic route segment. Fortunately, I configured middleware to implement i18n, making it look like a global not-found.tsx. |
Is global not-found supported??? I'm still experiencing this issue with the next version |
Link to the code that reproduces this issue or a replay of the bug
https://github.com/devjiwonchoi/multi-root-layout-not-found
To Reproduce
CodeSandBox Repro Link
/404
Current vs. Expected behavior
Current
The multi-root layout group routes cannot have a global not-found since they don't have
app/layout
.I'm trying to clarify how to handle the unmatched URLs if global not-found is not allowed in group routes with multi-root layouts.
Expected
IMO the expected behavior for
/404
is displaying the not-found inside the group which has app/(group)/page.tsx.Verify canary release
Provide environment information
Operating System: Platform: linux Arch: x64 Version: #1 SMP PREEMPT_DYNAMIC Sun Aug 6 20:05:33 UTC 2023 Binaries: Node: 16.17.0 npm: 8.15.0 Yarn: 1.22.19 pnpm: 7.1.0 Relevant Packages: next: 13.4.20-canary.23 eslint-config-next: 13.4.20-canary.23 react: 18.2.0 react-dom: 18.2.0 typescript: 5.2.2 Next.js Config: output: N/A
Which area(s) are affected? (Select all that apply)
App Router
Additional context
This issue extends #54980
The text was updated successfully, but these errors were encountered: