I have shared layouts for several logical groups of pages, for example:
DashboardLayout:/dashboard/foo/dashboard/bar
UserLayout:/user/settings/user/profile
Both DashboardLayout and UserLayout use data that has to be fetched on the server-side (e.g. from a database server).
How can I:
- fetch this data from the layout components when
getServerSidePropsonly works in page components; and - keep the fetching logic tied to the layouts and not the page components or the
Appcomponent; and - keep the layouts persistent (Next.js docs), i.e. prevent re-fetching/re-rendering when navigating between pages using the same layout (e.g. from
/user/settingsto/user/profile); and - ideally not use any third-party libraries nor shallow routing?