Hi!
I have a design question for my Next.js project regarding the best usage of Next.js features. I wanna create a website where the layout of all routes is structured exactly the same way. Every page needs to have a Breadcrumb as the first HTML element inside the root layout (code provided below). However the content of the Breadcrumb differs because each page has a different route, therefore, the Breadcrumbs should display specific Items for each route/page.
I tried creating a Context for the Breadcrumbs, so every page can change the BreadcrumbItems and the layout can include the BreadcrumbComponent. This method has the huge disadvantage, that all pages need to be Client Components - because every page needs the useEffect hook -, which is unnecessary.
Then I tried just including the BreadcrumbComponent on every page. This method works fine, but also has a huge drawback: I cannot use the functionality of layout pages anymore, because at the layout level, I dont know the content of the BreadcrumbItems, but on the specific pages level, I cannot include the BreadcrumbComponent because then the HTML element would not be the first inside the {children} of the root layout.
And this is my dilemma...
If I understood any concept of Next.js wrong - and the disadvantages are actually non-existent -, please correct me, so I can implement one of the above methods!
However, if the disadvantages are really limitations of Next.js and I'm not wrong, please let me know, if there is a common pattern or design guide for exactly such usecases. I have already ask Chatbots too many times and they only provide non working solutions...
Feel free to discuss as much as you like!
Link to GitHub repo:
https://github.com/Richter-glutenfreie-Produktions-GmbH/batch-management-system