Replies: 1 comment
-
|
You can’t directly fetch sidebar items from an API inside That file is executed at build time in Node.js, not in the browser, so:
Docusaurus requires the sidebar to be synchronous and static. ✅ Correct ways to achieve API-driven sidebarsOption 1 — Generate
|
| Goal | Solution |
|---|---|
| Dynamic sidebar from API | generate sidebars.js before build |
| CMS-driven docs | generate Markdown + auto sidebar |
| Runtime sidebar changes | use plugin + React UI only |
🚀 Summary
👉 You cannot fetch sidebar data directly inside sidebars.js.
The correct pattern is:
✔ Fetch API BEFORE build
✔ Generate staticsidebars.jsfile
✔ Let Docusaurus consume it normally
If this answer helped or pointed you in the right direction, I'd appreciate it if you could mark it as the accepted answer so it's easier for others with the same issue to find.
Also, if you found my contribution useful, I'd appreciate it if you could check out my GitHub profile, follow me, and star any repositories you find interesting.
GitHub: https://github.com/Advait251206
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
just want to know how to modify sidebars.js to get sidebar item from api.. thanks
Beta Was this translation helpful? Give feedback.
All reactions