BeforeNavigationEvent

So we can register an AfterNavigationListener to the UI to be notified of all navigation events after they are completed. Is there also something like that to get notified of a navigation event when it gets started? I know there is the BeforeLeaveEvent but that only gets dispatched to the components that are on the screen. I want to get notified of all navigation events when they are triggered. A counterpart of the AfterNavigationEvent.
Or is there another way to accomplish that?
Somewhat related: is it possible to get a list of the user’s navigation history within a UI?

BeforeEnter

could be an idea

BeforeEnterEvent? That only gets called in the components too doesn’t it? It’s the counterpart of BeforeLeaveEvent

I have a standalone listener that is not a component

It works for AfterNavigation but I need a BeforeNavigation too

Shameless copy from the docs:

BeforeLeaveEvent is the first event fired during navigation.

The event allows the navigation to be postponed, canceled, or changed to a different destination.

This event is delivered to any component instance implementing BeforeLeaveObserver that is attached to the UI before the navigation starts.

Just attach your listener to a component like the header, main, footer or any other component that is always on the UI

I mean I’m really not a fan of adding logic to a component that has nothing to do with that component, that’s why I like AfterNavigation, I can attach directly to the UI object

But if that’s the only way then I’ll do that yea

“Somewhat related: is it possible to get a list of the user’s navigation history within a UI?” - any idea about this?

Not directly but there you can access the History https://vaadin.com/docs/latest/advanced/history-api

Yea, that lets me navigate to a previous page but doesn’t tell me what that page was (which is fair I guess considering that’s your browser history, not just the in-app history)

I can track it myself but that’s tricky when I don’t know whether the user is navigating forwards or backwards