I currently try to set the title
of the page.
Scenario
public class A extends FlexLayout implements RouterLayout {}
@Route(value = "b", layout = A.class)
public class B extends FlexLayout{}
@Route(value = "c", layout = A.class)
public class C extends FlexLayout{}
Attempts
To do so I tried to call
UI.getCurrent().getPage().setTitle("demo title")
duringafterNavigation
. Unfortunately this does not work for the initial navigation (and neither worked adding anattachListener
).I also tried configuring it using the
PageConfigurator
on the outermostRouterLayout
like this:
@Override
public void configurePage(InitialPageSettings settings) {
settings.addMetaTag("title", "demo title");
settings.addMetaTag("og:title", "demo title");
settings.addFavIcon("icon", "frontend/images/favicon.ico", "48x48");
}
HasDynamicTitle
only seems to work if the implementing class also defines the@Route
but not the encapsulatingRouterLayout
Issue
For some reason the Router
itself sets the title during navigation.
The Router
defines the title using JS and redefining document.title
while Page.setTitle
seems to only modify the html.head.title
tag.
Question
How does one set the title in a single spot?
How does one prevent the Router
form setting the title to the value of the current URL?
Note
Using the @PageTitle
annotation is not an option as in my case the title is not known at compiletime.
UI.getCurrent().getPage().executeJavaScript("document.title = $0",your_title);
in yourattachListener
? And if this doesn't work then implement theBeforeEnterObserver
and call it insidebeforeEnter
. But aHasDynamicTitle
should work based on the documentation. So might be a bug :/ – VeachHasDynamicTitle
and adding that interface to each and everyRoute
endpoint. – JanessaRoute
has to know / remember that setting the interface is required. – Janessa