Folks, I have a RouterView that uses the layout setting. A part of the app logic needs to change the user name displayed by the AppLayout and have the AppLayout “refreshed” or “re-rendered” based on the update. Is there a way to do it?
@Route(value = "account", layout = AccountAppLayout.class)
public class AccountView extends VerticalLayout {
}
You should exploit here the fact that also the MainLayout afterNavigation is being called when you navigate to child views. MainLayout afterNavigation is executed first and then the one in the @Route class.
This should be the correct way to update MainLayout based on navigation, e.g. if you want to show breadcrumbs or something else on MainLayout.
You will see small GitHub icon in the menu Drawer. The link in that is updated based on the view you navigate via the menu. Your question is technically the same.
@Tatu2, it turns out, implementing BeforeEnterObserver is called at every route. So, I ended up with populating dynamic values there, plus using the event bus as @knoobie suggested for updating the L&F upon user-driven request.
Yes, BeforeEnterObserver is triggered in MainLayout in similar fashion on navigation as AfterNavigationObserver. However in your case AfterNavigtionObserver is semantically more correct.