BeforeEnter is called on navigation but not on reload

I am trying to process query parameters by using the values to configure a data provider’s filter. I tried both AfterNavigationObserver and BeforeEnterObserver and the callbacks are called when I go into a view with this component, or when I use the back button but not when I go to the URL directly or when I reload the tab.

Am I missing something or is this not working as it should?

I thought of combining those with onAttach but that one does not get Location :slightly_frowning_face:

Maybe more context would be useful. I have a grid view with several filters. I want to be able share links with query parameters corresponding to the filter values. So I need the filters to update the URL. And I need the URL to be parsed and set the filter values on view load.

Seems like a pretty common thing in UI and just seems impossible in Vaadin.

Those listeners are exactly used for such things and work. Please share code :wink:

Do you use @PreserveOnRefresh?
Btw I use AfterNavigationObserver interface and its afterNavigation(AfterNavigationEvent afterNavigationEvent) method in one of my project. Since this observer is notified after every navigation (not only where I implement) I have check the afternavigationEvent.getLocation().getPath() to handle the queries only in the appropiate view.
Maybe it would be nice to see your additional code to be more precise.

oh, so something must be broken on my end then… just to confirm beforeEnter is called even when directly accessing a URL in a fresh tab? is it called on just views with @Route or all components?

on Routes

And afterNavigation also works on routes only?

Depends - there are two types of observation methods, one that works on routes and one that works on any Vaadin class

Edit: this doesn’t hold true. The *Observer class can be on any Vaadin attached component / the other type is *Handler which should only be used UI-wide

Both seen to work on my non-route component when navigating within the app. Neither works on the initial load.

I can guarantee you that they also work on initial load. Sounds like something is wrong within your environment

On routes there are two ways for parameters: The setParameter() from HasUrlParameter<> and the beforeEnter from BeforeEnterObserver. The HasUrlParameter is used when the view is called directly and the beforeEnter when called via navigate. Perhaps the setParameter is working for you, too?

HasUrlParameter only works for route parameters for some reason. I want to use query parameters.

my routes are:
/audit-log
or with set filter:
/audit-log?filter1=value1&filter2=value2

but i also have:
/audit-log/<entity_id>
which shows a different view

Anyway, AfterNavigationObserver seems to work perfectly in all cases (including first load) when on @Route. It doesn’t work on initial load for non-route component. But I can work with this, I will just pass the state from the view into the components.

That explain it, the other components are probably not attached initial and therefore not informed

@adaptable-uakari I would propose updating the documentation around routing to make it more explicit that some things work only on @Route components.

I’m not a Vaadin employee. Please add a comment on the documentation page

good to know, my bad!

https://github.com/vaadin/docs/issues/1947 good issue to add your comment