How to base your Vaadin 14 app on a subclass of `UI` rather than the new Ro

In Vaadin 14.0.1, the newer [Routing feature]
(https://vaadin.com/docs/v14/flow/routing/tutorial-routing-annotation.html) is re-instatiating the views and UI objects of your app. So your user’s state is constantly wiped out. See [this thread]
(https://vaadin.com/forum/thread/17606829/navigation-via-router-api-creates-new-instance-of-destination-layout), [this thread]
(https://vaadin.com/forum/thread/17810577/ui-being-instantiated-over-and-over-again-in-default-vaadin-14-0-1-app), and [ticket # 6.321]
(https://github.com/vaadin/flow/issues/6321) for details. So it seems the Routing feature is useless, even detrimental.

How can we disable the Routing behavior, and use another approach?

Perhaps someone can post example code on how to start a Vaadin 14 app using the old-fashioned approach, where we wrote our own subclass of UI?

Or give links to older documentation showing this approach?

Or suggest some other way to build a Vaadin 14 app while avoiding Routing?

Is it the @PreserveOnRefresh annotation that you’re looking for? (In Vaadin 14)

https://vaadin.com/releases/vaadin-14#preserveonrefresh

S.

Stuart Robinson:
Is it the @PreserveOnRefresh annotation that you’re looking for? (In Vaadin 14)

https://vaadin.com/releases/vaadin-14#preserveonrefresh

S.

Nope. Using @PreserveOnRefresh reduces some of the inexplicable re-initialization or re-instantiation of the UI and other objects. But in all cases, routing wipes out your views and your UI, erasing all of your user’s state, poof, gone. The VaadinSession and its “attributes” may be the only user state left (I’ve not checked that yet.)

See the links I gave, for details. Very easy to see the problem for yourself with a new Vaadin 14 app, and adding a few lines of code.

Hi Basil,

I was reading through your other threads. Although the UI re-instantiating is odd and does need to be fixed, I’m not having any issue with saving state while navigating around in my app.

I started with Vaadin 10 for this app, so I was aware there was no @PreserveOnRrefresh and expected the UI object to be recreated (I think… it was a while ago :slight_smile: ).

So I just saved the sate in a @UIScope’d bean. My routes have a ParentLayout which doesn’t get recreated as I navigate around the app. At the moment the only time I loose state is if you manually change the URL.

Stuart

Stuart Robinson:
… My routes have a ParentLayout which doesn’t get recreated as I navigate around the app.

You apparently are doing something akin to the workaround suggested by Joni Uitto on [this thread]
(https://vaadin.com/forum/thread/17810577/ui-being-instantiated-over-and-over-again-in-default-vaadin-14-0-1-app).

At the moment the only time I loose state is if you manually change the URL.

Beware: My experiments in Vaadin 14.0.1 show that links using Anchor to visit another URL with routing does indeed replace the UI object with another. This happens even regardless of @PreserveOnRefresh.

Quite simple to see for yourself. Just attach a UIInitListener as [shown in the manual]
(https://vaadin.com/docs/v14/flow/advanced/tutorial-ui-init-listener.html).