Navigating between views.


Currenty I’m trying to create a registration form to practive navigating between views. I’ve got 3 views: DefaultView, LoginLayout and RegisterLayout. The problem is that I can’t switch between them and I can’t even set the DefaultView as a default one.

1st question: what is the second parameter in Navigation constructor? I used this one, but I think it’s not correct:
Navigator navigator = new Navigator(this, defaultView) → where default view is a new DefaultView(), of course.

2nd question: if I don’t set the default view, it works, but sends me an error: “trying to navigate to an unknown state…”. Obviously this happens because I didn’t set the a default one, but If I set the defaultView it doesn’t work…

Here is my short code, I think I’ve explained everything and you can understand my problem. " defaultVIew" has two button and I’ve added listeners to them to navigate …

defaultView.default_sign_in.addClickListener(clickEvent → { getNavigator().navigateTo(LoginLayout.VIEW_NAME); }); defaultView.default_registration.addClickListener(clickEvent → { getNavigator().navigateTo(RegisterLayout.VIEW_NAME); }); setContent(defaultView);
Navigator navigator = new Navigator(this, defaultView);
navigator.addView(“”, DefaultView.class);
navigator.addView(LoginLayout.VIEW_NAME, LoginLayout.class);
navigator.addView(RegisterLayout.VIEW_NAME, RegisterLayout.class);

Thanks for any help.


You need to learn to use docs :slight_smile:

and you dont need to setContent(defaultView) its done by navigator.

It’s the Navigator which will do the switching between views, based on which URL the browser is currently showing. So you don’t call setContent() directly - the Navigator will call it, to set the current View to any ViewDisplay registered to the navigator. So you don’t set the default view as a ViewDisplay since that would make views show inside the default view.

What you typically do is to set the UI as a ViewDisplay to the Navigator. Navigator will then use UI to show views; the default view will be any view that’s mapped to “”, by the means of navigator.addView(“”, DefaultView.class);