Introduction
🎯 What does this module do?
The Menus module lets you retrieve site navigation structures - header menus, footer menus, sidebar navigation, mobile menus - dynamically building multi-level navigation from pages configured in OneEntry.
Think of it as your navigation manager - you create menus in OneEntry admin panel (linking pages together), and this module fetches the complete menu tree structure, so you can render navigation dynamically without hardcoding links.
📖 Simple Explanation
Every website needs navigation to help users find content:
- Header Menu - Main navigation (Home, About, Services, Contact)
- Mobile Menu - Hamburger menu with dropdowns
- Sidebar Menu - Category navigation (Blog categories, product filters)
- Footer Menu - Legal links, social links, sitemap
- Mega Menu - Complex dropdowns with images and categories
- Breadcrumbs - Current page path (Home > Products > Electronics)
Issues:
- Hard to update - Need to redeploy code to change menu
- No multi-language support - Different menus for each language
- Not admin-friendly - Developers needed for every change
- Menu duplication - Same menu hardcoded in multiple places
The Menus solution:
Benefits:
- Easy updates - Change menus in admin panel, no redeployment
- Multi-language - Menus automatically localized
- Admin-friendly - Non-developers can manage navigation
- Single source of truth - One menu structure everywhere
✨ Key Concepts
What is a Menu?
A Menu is a navigation structure that contains links to pages:
- Menu Items - Individual navigation links (pages)
- Hierarchy - Nested structure (parent → children)
- Ordering - Display order of items
- Localization - Translated titles per language
- Dynamic - Fetch structure from API, render in your app
Menu Structure
Each menu has this structure:
{
id: 123,
identifier: "header_menu", // Unique identifier
localizeInfos: {
title: "Main Header Navigation" // Menu title
},
pages: [ // Menu items (pages)
{
id: 1, // Page ID
pageUrl: "/home", // Page URL
localizeInfos: {
title: "Home", // Display in page
menuTitle: "Home" // Display in menu
},
attributeValues: {}, // Attribute values
parentId: 0, // Top-level item
position: 1 // Display order
}
]
}
Menu Hierarchy
Menus support nested structures (multi-level navigation):
📂 Header Menu
├─ 🏠 Home (depth: 0, parentId: 0)
├─ 📖 About (depth: 0, parentId: 0)
│ ├─ 👥 Team (depth: 1, parentId: 2)
│ ├─ 🏢 Office (depth: 1, parentId: 2)
│ └─ 📜 History (depth: 1, parentId: 2)
├─ 🛍️ Products (depth: 0, parentId: 0)
│ ├─ 💻 Electronics (depth: 1, parentId: 4)
│ │ ├─ 📱 Phones (depth: 2, parentId: 5)
│ │ └─ 💻 Laptops (depth: 2, parentId: 5)
│ └─ 👕 Clothing (depth: 1, parentId: 4)
└─ 📞 Contact (depth: 0, parentId: 0)
Common Menu Types
| Menu Type | Description | Example Use Cases |
|---|---|---|
| Header Menu | Main site navigation | Top navigation bar, primary links |
| Footer Menu | Footer links | Legal, social, sitemap |
| Sidebar Menu | Category navigation | Blog categories, product filters |
| Mobile Menu | Mobile-specific navigation | Hamburger menu, drawer menu |
| Mega Menu | Complex dropdown with categories | E-commerce multi-level navigation |
| Breadcrumbs | Current page path | Home > Products > Electronics |
Why Use Menus Module?
| Benefit | Description |
|---|---|
| Dynamic Navigation | Fetch menu structure from API, no hardcoding |
| Multi-Language | Menus automatically localized based on locale |
| Admin-Friendly | Non-developers can update navigation |
| Hierarchical Structure | Support for nested menus (unlimited depth) |
| SEO-Friendly | Proper page relationships and structure |
| Single Source of Truth | One menu structure used everywhere |
📋 What You Need to Know
Menus are Created in Admin Panel
You cannot create menus via the SDK - they're created in the OneEntry admin panel:
OneEntry Admin Panel → Menus → Create Menu → Add Pages → Save
The SDK is for fetching menu structures, not creating them.
Menu Items are Pages
Important: Menu items are pages configured in OneEntry. You cannot add arbitrary links to menus - every menu item must be a page.
Menu Hierarchy (Parent-Child Relationships)
Menus support unlimited nesting depth
💡 Important Notes
Menus are Created in Admin Panel
Remember: The SDK is for fetching menu structures, not creating menus.
To create/edit menus: Use OneEntry Admin Panel or Admin API.
Menu Items Must Be Pages
You cannot add arbitrary links to menus. Every menu item must be a page configured in OneEntry.
Workaround for external links: Create pages with external URLs in OneEntry, then add them to menus.
Menu Hierarchy is Flexible
Menus support unlimited nesting depth - you can have as many levels as needed.
Multi-Language Support
Menus automatically support multi-language based on langCode in defineOneEntry().
Best practice: Fetch menus in user's preferred language.
Cache Menus for Performance
Menus rarely change - implement caching to reduce API calls:
- Frontend: localStorage, sessionStorage
- Backend: Redis, memory cache
- TTL: 1 hour recommended
📊 Quick Reference Table
| Method | Description | Use Case |
|---|---|---|
| getMenuByMarker() | Get menu by marker | Fetch specific menu structure |
❓ Common Questions (FAQ)
How do I create a multi-level menu (dropdown navigation)?
Menus support unlimited nesting depth. Use parentId to create hierarchical structures.
In the admin panel, you can nest pages to create parent-child relationships that automatically reflect in the menu structure.
Can I add external links to menus?
Menu items must be pages configured in OneEntry. To add external links, create pages with external URLs in the Pages module, then add them to your menu.
How do I handle the active menu item state?
Compare the current page URL with each menu item's pageUrl.
Apply an active class/style when they match to highlight the current page in navigation.
My menu has too many items. How do I optimize performance?
Cache menus using localStorage or sessionStorage since they rarely change. Implement lazy loading for mega menus with many nested items. Consider using a mobile-optimized hamburger menu for better UX.
How do I create a breadcrumb navigation?
Use the menu hierarchy to build breadcrumbs.
Trace from the current page up through parentId relationships to build the breadcrumb path (Home > Category > Subcategory > Current Page).
Can I have different menus for different sections?
Yes! Create multiple menus with different markers (e.g., header_menu, footer_menu, sidebar_menu) and fetch them separately using getMenuByMarker().
🎓 Best Practices
- Use markers, not IDs - Markers are stable across environments
- Cache menus - Reduce API calls for rarely-changing data
- Build recursive tree - Use parentId for hierarchical structure
- Sort by position - Respect display order
- Handle active state - Highlight current page
- Provide fallback menus - Handle errors gracefully
- Support multi-language - Use langCode for localization
- Optimize for mobile - Implement responsive navigation
More information about the module's user interface https://doc.oneentry.cloud/docs/menu/introduction_menu
Definition of the Menus module
The Menus module defines the structure and navigation of your site.
The menu is a key element of the structure and navigation of your site. With the menu, you provide visitors with a convenient way to navigate through different sections of your application and find the information they need.
const { Menus } = defineOneEntry( "your-project-url", { "token": "your-app-token" });
In OneEntry Platform, you can create the menu structure directly from your personal account. This allows you to change the set of pages included in the menu, their order, and titles without modifying the source code of your application.
Additionally, if necessary, you can create nested levels in the menu, allowing for a tree-like structure with sections and subsections.
All of this enables you to work conveniently and flexibly with the navigation of your application directly from your personal account.
At the core of the menu are pages. The menu structure is created from pages.
You can define:
Which pages will be included in the menu In what order they will be presented to the user What title will be given to the menu item leading to a specific page The nesting of menu items (Tree structure) Some of these concepts were discussed in the pages section, and some page settings affect the menu structure you can create from these pages.
🔗 Related Documentation
- Pages Module - Manage pages that make up your menus
- Locales Module - Multi-language support for menu localization
- GeneralTypes Module - Page types used in menus