Page title construction in RouterLayout issue
See original GitHub issueDescription of the bug
After these changes in Vaadin Flow
It’s not possible to construct custom page title outside of each view. Navigation lifecycle always rewrites title at the end, so it seems that there is no places left where we can call Page.setTitle("custom title")
.
Expected behavior
It’s must be possible to set custom page title after navigation finished
Minimal reproducible example
Minimal example from the real app: https://github.com/gigi/vaadin-23-pagetitle-issue
Main idea is to avoid service dependencies coupling and delegate control of common UI elements to layouts.
So there is custom PageChangedEvent event which can be used for updating layout menu, breadcrumbs construction, setting page title etc. This event is fired in After Navigation stage. Before these changes it was possible to construct page title and set it by hand: https://github.com/gigi/vaadin-23-pagetitle-issue/blob/main/src/main/java/com/example/demo/layout/BasicLayout.java#L50
Possible solutions:
- Add support of
HasDynamicTitle
in the RouterLayout that has higher priority than Router’sgetPageTitle
or vice versa - Concatenate page title somewhere in response listeners (I don’t know where exactly and how to handle title template properly)
- Inject necessary layout dependencies in each view and construct title in
getPageTitle
(quite annoying)
Versions
- Vaadin: 23.1.0.rc1
- Flow: 23.1.0.rc2
- Java: BellSoft 17.0.3
- OS: x86_64 Mac OS X 12.3.1
- Browser: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.64 Safari/537.36
Issue Analytics
- State:
- Created a year ago
- Comments:8 (4 by maintainers)
Top GitHub Comments
For me it makes sense to use
HasDynamicTitle
from first available parent layout if it implements such. It is easily accessible from active router target chain.As for overriding title which was set duringAfterNavigation
- we could introduce a flag that will be set after title has been already set and will prevent triggering defaultAbstractNavigationStateRenderer.updatePageTitle
.After above change view updates title by
PageChangedEvent
onafterNavigation
and Flow reads a title value from first parent layout.Thanks @gigi for example project, it helped a lot.
This ticket/PR has been released with Vaadin 24.0.0.alpha6 and is also targeting the upcoming stable 24.0.0 version.