Assuming my view is:
@Route(value="test")
public class TestView extends VerticalLayout implements BeforeEnterObserver {
public TestView() {
super();
// do some stuff.
new Button("Test", click -> getUI().ifPresent(ui -> ui.navigate("test")));
}
@Override
public void beforeEnter(BeforeEnterEvent event) {
// do some other stuff.
}
}
If I click on the Test button above then the constructor is not instantiated however the beforeEnter()
method is called. In my case I would much prefer to instantiate the whole view class because the beforeEnter()
method includes some logic and setup code that the view needs that if called twice can mess up the components. Specially the beforeEnter()
does some checks and depending on the details may call different component rendering paths.
Please try the code below. It removes the view (navigation target) instance from UI and then calls page reload on the client side. Then, after page reload, the next request to server will force creating a new instance of the view.
Output:
Hope this is something you wanted to reach.