RouteScoped explained


I tried to use @RouteScoped a Route component. After reading the docs, I assumed that means that whenever the route is active (is navigated to), the bean is first created, and might only be destroyed when navigating away from it.
What I see that is when navigating to the route, it is created but also directly destroyed. (onAfterNavigation triggers com.vaadin.quarkus.context.RouteScopedContext$ContextualStorageManager.destroyDescopedBeans)

The idea I had was to create some Object that is the same for as long as a certain route is active, but if the RoutescopeOwner is immediately destroyed, then I guess this won’t work.
Is this intended behavior or not?

(vaadin 24.0.7 on quarkus 3.0.3)

Thanks !

that is the same for as long as a certain route is active
How you define a route being active, what it means exactly.

indeed, I assumed it was as long as I was on the page (that was annotated with RouteScoped RouteScopeOwner) that the RouteScope was active, but maybe routescope then means if you navigate to the page, the routescope immediately ends?

It depends on what you define as owner, as there is a hierarchy. If you use the RouterLayout, e.g. MainLayout as RouteScopeOwner, the lifecycle is defined by it. So if you have two child views and autowire RouteScoped bean whose lifecycle is defined by MainLayout to them, they will share the same instance. If you define the child view to be the RouteScopeOwner the bean lifecycle is defined by the child view, and you will get a new instance when you navigate to that child view.