Next.js Discord

Discord Forum

not-found.tsx inside route groups

Answered
Checkered Giant posted this in #help-forum
Open in Discord
Checkered GiantOP
Can someone help me I have this problem where I have 2 route groups with 2 layout.tsx however I want to add a not-found.tsx but I can’t because I don’t have a global layout and putting the not-found.tsx inside one of the route groups doesn’t work. Thanks
Answered by Clown
Put your providers in the route group layouts and in global root layout just return the children without any changes.
View full answer

16 Replies

Checkered GiantOP
cuz I have 2 whole different layouts with different providers on each of the layouts
Nah it gives me the default nextjs 404
@Checkered Giant cuz I have 2 whole different layouts with different providers on each of the layouts
Using a global layout is like surrounding your component with a div tag
It wont change anything
technicality you can import the layout form the group and import it into the root 404 page...
Checkered GiantOP
wouldn it mess with the performance if I have like 4 providers that aren’t even used on one side of the website
@riský technicality you can import the layout form the group and import it into the root 404 page...
Checkered GiantOP
Wdym I did but it says it needs a layout
@Checkered Giant wouldn it mess with the performance if I have like 4 providers that aren’t even used on one side of the website
As i said, you can literally take the children from the param and return it
Checkered GiantOP
Ok I’ll try it brb
Also unless the route group is active the layout wont be loaded(iirc)
Put your providers in the route group layouts and in global root layout just return the children without any changes.
Answer
I didn’t know you can still have a global layout if you already have them in the route groups
you can have a route group for any folder...