You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TLDR: Is there any way to dynamically build paths and get StaticProps at the _app level? I want to 1) Build Entire tree of NavData from filesystem and 2) Manage which data is fed to the Nav based on dynamic route.
I'm trying to build a site similar to the Stripe Docs, and I want both the header with its MainNav and the SidebarNav to be a lop level component defined in a Layout component so I can have persistence of the Navigation between pages.
I'm using a getLayout function attached as a static property to each page to handle this as suggested in this blog post by TailwindJS creator.
What I would like to do and am unsure how to do, is I would like to build the Sidebar navigation off of the filesystem. For example if I have a Subjects folder with "physics", "math", "chemistry" content directories, I would like the SideNav at build time to look and automatically build navigation values off of these file systems, that way I can add some later and they will automatically be included in the navigation. If _app had a getStaticProps function this would be easy, but that doesn't seem to exist yet.
Also, I want to change the visible SideNav values based on the route. So if it's 'learn/physics' then the physics nav data will be fed to SideNav. However, I'm using the [...subjects].js static page pattern, and when I navigate to a page like 'learn/physics', Next router feeds me 'learn/[...subject]' as the path.
Is there any way to dynamically build paths and get StaticProps at the _app level? Or do I have to push all of this work of managine the SideNav and its data down to the page level and lose page to page persistence of having a top level component?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
TLDR: Is there any way to dynamically build paths and get StaticProps at the _app level? I want to 1) Build Entire tree of NavData from filesystem and 2) Manage which data is fed to the Nav based on dynamic route.
I'm trying to build a site similar to the Stripe Docs, and I want both the header with its MainNav and the SidebarNav to be a lop level component defined in a Layout component so I can have persistence of the Navigation between pages.
I'm using a getLayout function attached as a static property to each page to handle this as suggested in this blog post by TailwindJS creator.
Example:
What I would like to do and am unsure how to do, is I would like to build the Sidebar navigation off of the filesystem. For example if I have a Subjects folder with "physics", "math", "chemistry" content directories, I would like the SideNav at build time to look and automatically build navigation values off of these file systems, that way I can add some later and they will automatically be included in the navigation. If _app had a getStaticProps function this would be easy, but that doesn't seem to exist yet.
Also, I want to change the visible SideNav values based on the route. So if it's 'learn/physics' then the physics nav data will be fed to SideNav. However, I'm using the [...subjects].js static page pattern, and when I navigate to a page like 'learn/physics', Next router feeds me 'learn/[...subject]' as the path.
Is there any way to dynamically build paths and get StaticProps at the _app level? Or do I have to push all of this work of managine the SideNav and its data down to the page level and lose page to page persistence of having a top level component?
Beta Was this translation helpful? Give feedback.
All reactions