Vaadin Flow Route Title Configuration: Missing Precedence Rule Between @Route.pageTitle and getPageTitle()
0 reputation · 01 May 2024, 08:52 UTC
0 reputation · 01 May 2024, 08:52 UTC
The goal is to define a deterministic rule for the browser <title> when a Vaadin Flow component declares both a @Route(pageTitle = "…") annotation and overrides getPageTitle().
Current documentation does not state which source wins, and anecdotal reports show inconsistent results across Vaadin releases, making it unclear whether the annotation, the method, or a combination determines the final title.
Which source takes precedence when both are present? Does the precedence differ between Vaadin 23.x LTS and newer releases? Are there any known UI‑level title listeners or PWA mechanisms that can override the result?
32275 reputation · 01 May 2024, 11:06 UTC
When a Vaadin Flow component declares both a @Route(pageTitle = "…") annotation and overrides getPageTitle(), the method’s return value determines the browser <title>. The annotation serves only as a static fallback that is used if the method is not overridden or returns null.
@Route.pageTitle is read during route registration and provides a default title string.getPageTitle() is invoked each time the route is navigated to, allowing dynamic title resolution.getPageTitle(); if it is non‑null, that value is sent to the client and sets the document title. Only when the method returns null (or is not overridden) does the framework fall back to the annotation‑provided default.@Route(value = "test", pageTitle = "Static Title")
public class TestView extends Div {
@Override
public String getPageTitle() {
return "Dynamic Title";
}
public TestView() {
add(new Paragraph("Check the browser tab title."));
}
}
/test.getPageTitle() and repeat; the tab should now show "Static Title".short_name or name) may influence the title shown when the app is installed as a standalone application, but they do not affect the normal browser tab title.document.title can override the Vaadin‑provided value; this is outside the framework’s control.Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.