Navigation without recreating views

In the HelloWorld and About views are recreated when navigating. Is it possible to configure the routing to reuse the view instances instead?

I have tried adding @UIScope to the views, but they are still recreated. Even with @funny-manateeSessionScope they are still recreated.
Did I miss something?

It depends how / where you init your views. VaadinSessionScope should nevertheless never be used for any views of components

I have a similar setup using AppLayout in my application, and shouldn’t the Vaadin router take care of this?

Shouldn’t also the demo app work so that adding @UIScope to the HelloWorld and About views prevents them from being recreated. I am thinking this is a defect?

Please show code where you think it’s broken or what’s miss-behaving

It’s calling the constructor of the HelloWorld and About views each time I navigate, which I want to prevent. And it cannot be done with @UIScope.

Are you using spring’s method security or other means that enforce proxying?

No, it is just the default settings when generating the demo app from

You need to ad @SpringComponent annotation to your view

Here’s a quote from docs

Routing components are Spring-initialized beans
All Flow routing components (@Route, RouterLayout or HasErrorParameter) are initialized by Spring, even without explicitly adding the @SpringComponent annotation. Without any annotations, the components act like a bean in prototype scope. You can inject other beans to the components, but while @PostConstruct methods work, @PreDestroy methods don’t. When you want to use another scope for the components, you need to remember to add the @SpringComponent annotation to get the scope applied.

As you can see, if you don’t add the annotation the view behaves like a prototype bean

Thanks Marco :man_bowing: was just looking for that

ah, ok, maybe the starter app should add this, should I add a request for that?

I verified that the views behaves as I want with the @SpringComponent annotation. (even without @UIScope)

@SpringComponent annotation without any scope = the view is a singleton = one shared view for all the users.
That should never be done.
Always use a scope RouteScope, UIScope (unique per UI) or Scope(prototype) (created everytime you navigate from a different view.

so then I would like examples like the one in to have @UIScope and @SpringComponent added since I believe most users would benefit from not recreating the views each time navigation occurs.

That’s totally up to the Developer, prototype is the default for reasons :wink: