Retrieve the current view from navigator?

is there a way to retrieve the current view from navigator? I was trying to update a view, from a component that does not have direct access to that view, but it has acceses to the navigator, I tryed something like this:

if(navigator.getDisplay() instanceof InboxView){
( (InboxView) navigator.getDisplay()).refresh();
}

After I checked, now I know that the getDisplay does not get me the current View but a ViewDisplay, but I dont see how to access InboxView to call the methot refresh() on my view.

Hi,

there’s no direct way to access the current view (which is kind of stupid imho, maybe file a ticket?), but you can get it with a com.vaadin.navigator.ViewChangeListener. When you get the event, there’s a newView field which will basically be your “current view” until the next navigation happens. You can just store the reference from the latest event somewhere and call refresh for the view when needed.

-tepi

Please vote for https://github.com/vaadin/flow/issues/4565

Seems to be implemented since V24
UI.getCurrent().getCurrentView();