Skip to content

Navigation and menus

Navigation in Mateu is derived from your object model.

You declare menus as annotated fields. Mateu generates the navigation structure, sidebar, breadcrumbs and routing automatically.


The most common case. A @Menu field that points to another class generates a menu entry that navigates to that class’s UI.

@Menu
Products products;
@Menu
Changes changes;
  • The class is a mount (@UI) or is bound to a route in routes.yaml
  • The menu label is the field’s @Label, else the field name humanized (products → “Products”) — not the target class’s name or @Title
  • The instance is created and managed by Mateu (or Spring, if it is a bean)

A @Menu field of type String generates a navigation link to that path.

@Menu
String page3 = "/page3";

Use this when the target already has a @UI mount or a routes.yaml route elsewhere, and you only want a link to it.


A RouteLink lets you specify a route and a custom label explicitly.

@Menu
RouteLink page4 = new RouteLink("/page4", "Page 4");

Use RouteLink instead of a plain String when you need a label different from the field name.


A RemoteMenu fetches navigation items from a remote Mateu service.

@Menu
RemoteMenu workflow = new RemoteMenu("http://localhost:8105/_workflow");

The remote service exposes its own @Menu structure. The shell fetches and merges it into the navigation at runtime. That fetch is cached briefly per remote and caller — see descriptor caching for the TTL and how to tune it.

Give the entry a label when you want the shell to name the section — it then stays, whatever the remote calls itself, and the menu does not change under the reader when the remote answers:

@Menu
RemoteMenu booking = new RemoteMenu("/_booking").withLabel("Call center");

A remote that is down leaves its section dimmed and retried, not a broken shell; on a cold load the section and the first breadcrumb are known before the remote answers. See how the menus are merged.

This is the foundation of the distributed backoffice pattern: each microservice owns its UI, and the shell composes everything.


A @Menu field that points to a class which itself has @Menu fields creates a nested menu group.

// In Home2
@Menu
NestedApp nestedApp;
// NestedApp defines its own sub-menu
public class NestedApp {
@Menu
Page1 page1;
@Menu
Page2 page2;
}

NestedApp becomes a menu section header. Page1 and Page2 appear under it.

A group has a route of its own (/nestedApp; a type: Menu of a YAML shell gets its label camel-cased, Solar system → /solarSystem). Opening it — typed, bookmarked or from the menu — shows an index of the group’s entries, titled with the group’s label, rather than “Page not found”.

Route nesting (a sub-route that renders inside a parent screen’s slot) is declared as data in routes.yaml with children:, not by an annotation.

A group can open as a panel of cards instead of a plain dropdown, like the product menus of a documentation site: each entry is a card with a title, a description and an icon or image. Declare it on the field that holds the group, and describe each entry with @Menu(description, image) and @Icon:

public class Bookings {
@Menu NewReservation newReservation;
@Menu(display = MenuDisplay.cards)
QuickAccess quickAccess;
}
public class QuickAccess {
@Menu(description = "Sign the registration card and scan the ID")
@Icon(IconKey.Clipboard)
RegistrationCard checkIn;
@Menu(description = "Rooms coloured by housekeeping status", image = "/img/floor.png")
FloorPlan floorPlan;
// an entry with its own entries is not a destination: its entries are the card's ACTIONS
@Menu(description = "Folios, charges and payments")
@Icon(IconKey.Invoice)
BillingActions billing;
}
public class BillingActions {
@Menu Billing folio;
@Menu NewReservation newReservation;
}
  • Card: the entry’s label is the title, description the text, image (a URL relative to the app, or a data URI) or @Icon the visual. Clicking it navigates like any entry.
  • Actions: an entry that holds entries shows them as links on its card; the card itself does not navigate.
  • A group without display = cards, and every entry outside one, renders exactly as before.
  • In code (MenuSupplier, AppSupplier, fluent AppShell), set it with menu.withPresentation(MenuPresentation.cards()) on the group and withPresentation(MenuPresentation.card(icon, image)) / withDescription(...) on its entries.
  • .NET: [MenuGroup("Bookings", Display = MenuDisplay.Cards)] + [MenuItem(..., Description, Icon, Image)]; Python: @menu_group("Bookings", display=MenuDisplay.cards) + @menu_item(..., description=, icon=, image=) (see each port’s README).

Where it shows: in the top navigation bars — MENU_ON_TOP and the section band of HAMBURGER_SECTIONS — on Vaadin (mateu-card-menu) and Redwood (oj-popup with oj-action-cards). The native renderers draw the cards inside their drawer / sidebar (React Native: bordered cards with image, title, description and action chips; IntelliJ: two-line rows with icon and inline action links). Drawer and rail variants on the web, and the narrow-viewport ☰ button, keep the plain list. On the wire it is display: "cards" on the group’s MenuOptionDto and image on its entries.


6. Empty String (a route named after the field)

Section titled “6. Empty String (a route named after the field)”

A @Menu String field with no value is not a placeholder: it becomes a link to a route named after the field, under the app’s route (xxx → <app route>/xxx, kebab-cased), labelled like any other entry. Unless something answers that route (a routes.yaml entry, a @UI mount), clicking it shows “Page not found”.

@Menu
String xxx; // → <app route>/xxx

For a section header with no page of its own, use a nested ViewModel instead.


Every menu leaf above is a route — clicking it navigates. The other primitive is a rule: a leaf that runs a client-side action instead of navigating. A @Menu field typed Rule (or List<Rule>) becomes a rule leaf.

import io.mateu.uidl.data.Rule;
import io.mateu.uidl.data.RuleAction;
@Menu
Rule refresh =
Rule.builder().action(RuleAction.RunAction).actionId("refreshAll").build();
  • RunAction dispatches the action (the same path a FAB/header action uses), so “a menu item that runs something on the server” is a rule, not a special third kind of entry.
  • RunJS runs a statement client-side.
  • Clicking the leaf runs the rules; it does not navigate.

So the whole menu-leaf surface reduces to two things: a route (with the parameters, state and data it carries — see the route registry) or a rule.

When the RunAction rule names an action the app shell declares with steps — a flow — the leaf runs that flow client-side, with no server round-trip, so it works in a static bundle and in the visual editor’s Play too. In YAML:

type: AppShell
actions:
- id: newOrder
steps:
- type: Navigate
route: orders/new
menu:
- type: RuleLink
label: New order
rules:
- action: RunAction
actionId: newOrder

In code, AppShell.builder().action(Action.builder().id("newOrder").steps(List.of(new Step.Navigate("orders/new"))).build()) plus the same RuleLink. A Navigate to a route of the app stays inside the shell; an id the shell does not declare with steps is dispatched to the server as before. See App shell as data → Flows on the shell.


@UI("/home2")
@Title("My first Mateu app")
public class Home2 {
@Menu
Products products; // ViewModel → generates list/CRUD UI
@Menu
Changes changes; // ViewModel → custom listing
@Menu
NestedApp nestedApp; // ViewModel with sub-menus
@Menu
String xxx; // → <app route>/xxx (see §6)
@Menu
String page3 = "/page3"; // Route string
@Menu
RouteLink page4 = new RouteLink("/page4", "Page 4"); // Route + custom label
@Menu
RemoteMenu workflow = new RemoteMenu("http://localhost:8105/_workflow"); // Remote
}

Menu app — top navigation with Section 1 and Section 2 tabs


When a class is navigated to from a menu, Mateu needs to know where it sits in the route tree.

Declare it as an inner route of the parent mount — a type: Routes file tagged with the mount’s basePath (routes are relative to it; use children to nest a route in another route’s slot):

public class NestedApp {
@Menu
Page1 page1;
@Menu
Page2 page2;
}
# src/main/resources/specs/ui/home2-routes.yaml — the inner routes of the @UI("/home2") mount
type: Routes
basePath: /home2
routes:
- route: xxx
viewModel: com.example.NestedApp

This tells Mateu:

  • /home2/xxx is a route of the /home2 mount, answered by NestedApp — a page of its own. A flat entry under basePath is not a slot child: to render a route inside another route’s slot, nest it under that route with children: (or give it a parent:).
  • the entries under NestedApp (Page1, Page2) come from its own @Menu fields — the routes file does not create menu items.

Routes can contain parameters:

public class ExampleParametersViewModel {
String name; // populated from :name in the URL
int version;
@ReadOnly
String assessment;
@Button
void check() {
assessment = "name= " + name + ", version=" + version;
}
}
src/main/resources/specs/ui/routes.yaml
type: Routes
routes:
- route: example/:name
viewModel: com.example.ExampleParametersViewModel

Mateu populates name from the URL segment automatically when the page is navigated to.


@UI is the only routing annotation; inner routes are data. The difference is in context:

Declared withUse when
@UI("/path")Top-level entry point (mount) of the application or a module
a routes.yaml entryA page nested under a @UI mount, or bound to a CRUD flow
@UI("/users") // top-level
public class UsersPage extends AutoCrud<User> {
@Override
public CrudStore<User> store() {
return new UserStore(); // your CrudStore<User>
}
}
public class UserEditorPage {} // bound to the /users CRUD in routes.yaml
src/main/resources/specs/ui/routes.yaml
type: Routes
routes:
- route: users/:id/edit
viewModel: com.example.UserEditorPage

The whole shell — chrome and menu — can be composed in code instead of with @App/@Menu, computed at request time so the menu can depend on the user, configuration or a database. Implement AppSupplier on the @UI class and return a fluent AppShell; or implement MenuSupplier to compose just the menu and keep the rest of the shell declarative.

@UI("/back-office")
public class BackOffice implements AppSupplier {
@Override public AppShell getApp(HttpRequest request) {
return AppShell.builder()
.title("Back office")
.variant(AppVariant.HAMBURGER_MENU)
.homeRoute("/home")
.menu(List.of(
new RouteLink("/home", "Home"),
new Menu("/reports", "Reports", List.of(
new RouteLink("/sales", "Sales"))), // → /back-office/reports/sales
// A leaf can also RUN a rule instead of navigating:
new RuleLink("Approve", List.of(Rule.builder().actionId("approve").build()))))
.build();
}
}

Routes are relative: a top-level entry to the mount (/home → /back-office/home) and an entry inside a Menu to its group (/sales → /back-office/reports/sales). The full path is understood too: an entry that already starts with the mount (/back-office/home) or with its group’s path (/back-office/reports/sales inside /back-office/reports) is routed once, not repeated in the URL — the same in Java, .NET and Python.

The menu is a List<Actionable>, so both leaf kinds compose — a RouteLink/ContentLink that navigates and a RuleLink that runs client-side rules (the route-or-rule leaf) — plus Menu sub-trees and RemoteMenu federated entries.

Two more entries complete the set:

  • MenuSeparator — a divider between entries (new MenuSeparator(), YAML type: MenuSeparator). It draws a line in the menus that support one (the drawer, a Directory) and is skipped where a divider has no meaning.
  • MethodLink — an entry that runs a method of a class instead of opening a page: new MethodLink("/refresh", "Refresh data", Maintenance.class, "refresh"). Selecting it creates the class like a page and calls the method; what the method returns (a Message, a component, a navigation) is the answer, as for any action.
public class Maintenance {
public Message refresh() {
return new Message("Data refreshed");
}
}
List<Actionable> menu = List.of(
new RouteLink("/home", "Home"),
new MenuSeparator(),
new MethodLink("/refresh", "Refresh data", Maintenance.class, "refresh"));

Parity. AppSupplier/MenuSupplier (Java), IAppSupplier/IMenuSupplier + AppShell (.NET) and AppSupplier/MenuSupplier + AppShell (Python) all compose the shell + menu in code, overriding the static declarations; a field the shell leaves unset falls back to the declared @App/[App]/@app value. Routes are likewise code-authorable — see the route registry.

  • @Menu field type determines what kind of entry is generated
  • routes.yaml (basePath, children) declares where a page sits in the route tree
  • @UI declares a top-level entry point
  • Nesting is achieved by pointing @Menu fields at classes that themselves have @Menu fields
  • RemoteMenu lets the shell pull navigation from another service at runtime

See it live in the Explorer: Menus and routes in code · Card menus & rule leaves · App shell variants