App router - Placeholder files/pages that are handled by the layout file?
Unanswered
Carolina Wren posted this in #help-forum
Carolina WrenOP
I have a layout file that assigns the current component based off of the current pathName.
I set it up that way instead of one page with conditional components because I wanted the actual route to change (multi-stage form situation that can be saved as draft and returned to).
But the result is that all the page.tsx routes under the layout don't actually return anything - they just exists so that the route exists and can be handled by the layout.tsx file. This makes me feel like I'm likely not doing it the most effective way.
Attached a picture of the layout code and folder structure. All the page.tsx files just return an empty function.
Note: There is also a non-initiation section that uses the FormLayout component but not the layout.tsx, in case that explains anything that looks weird here. Also, yes, I haven't added error handling anywhere yet.
I set it up that way instead of one page with conditional components because I wanted the actual route to change (multi-stage form situation that can be saved as draft and returned to).
But the result is that all the page.tsx routes under the layout don't actually return anything - they just exists so that the route exists and can be handled by the layout.tsx file. This makes me feel like I'm likely not doing it the most effective way.
Attached a picture of the layout code and folder structure. All the page.tsx files just return an empty function.
Note: There is also a non-initiation section that uses the FormLayout component but not the layout.tsx, in case that explains anything that looks weird here. Also, yes, I haven't added error handling anywhere yet.
3 Replies
There is no need to do what you are doing in layout. As essentially you are just trying to replace what nextjs already does for you. Seems counter-intuitive and not sure what benefit you are hoping for.
Carolina WrenOP
How would you set it up otherwise though? Just duplicate the code for each page?
You just have the content you want on each page in that page.tsx file. The layout is better kept for thing slike your navbars/sidebars that don't change per page.