Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
View Duplication on Browser Back Button Press
Hello, I did not manage to find a similar problem description on any of the forums, so I am posting it here.
I am using Navigator in my Vaadin-Spring application as stated here.
The problem arises when the view is changed from default to some other view and then changed back to the default (does not matter programmatically or by typing uri fragment directly in browser).
So when the default view loads, the view itself is doubled, i.e the window horizontally splits and I have two instances of the default view, and when again going to some other view and back, the previous doubled view is multiplied by 2, and so on and on...
Example:
- navigating to the default view: http://localhost:8080 (result: default view is displayed OK)
- navigating to some other view: http://localhost:8080/#!register (result: some other view is displayed OK)
- pressing browser back button: http://localhost:8080/# (result: default view is displayed doubled PROBLEM)
or
- directly typing in browser: http://localhost:8080/# (result: default view is displayed doubled PROBLEM)
See image attached.
Please note that it is not the case when typing the http://localhost:8080 address without any trailing /# (forward slash and hash symbols)
So the question is the following is there any workaround to get rid of /# or am I doing wrong?
Thanks.
MainUI class with init method.
@Theme("mytheme")
@SpringUI(path = "")
public class MainUI extends UI {
@Autowired
private SpringViewProvider viewProvider;
@Override
protected void init(VaadinRequest vaadinRequest) {
Navigator navigator = new Navigator(this, this);
navigator.addProvider(viewProvider);
navigator.addViewChangeListener(new ViewChangeListener() {
@Override
public boolean beforeViewChange(ViewChangeEvent viewChangeEvent) {
return true;
}
@Override
public void afterViewChange(ViewChangeEvent viewChangeEvent) {
}
});
}
}
Thanks. I was expecting to see something strange in how the navigator and viewprovider are configured, but they seem to be all right. I don't know what could be the reason. Are you accidentally adding somewhere a second Navigator or adding content manually in some listener to the UI?
Just checked everything, commented out other classes with views implementation and left some for bug reproducing purposes.
1. The MainUI is posted above.
2. Default view SignInView
@UIScope
@SpringView(name = "")
public class SignInView extends VerticalLayout implements View {
@Override
public void enter(ViewChangeListener.ViewChangeEvent viewChangeEvent) {
Notification.show("Sign In");
setSizeFull();
AbsoluteLayout layout = new AbsoluteLayout();
layout.addComponent(new Button("new"), "left: 50px; top: 50px;");
addComponent(layout);
}
}
3. And the second view RegisterView
@UIScope
@SpringView(name = "register")
public class RegisterView extends VerticalLayout implements View {
@Override
public void enter(ViewChangeListener.ViewChangeEvent viewChangeEvent) {
Notification.show("Register");
}
}
4. Vaadin servlet configuration
@WebServlet(value = "/*" ,asyncSupported = true)
@VaadinServletConfiguration(productionMode = true, ui = MainUI.class)
public class VaadinServlet extends SpringVaadinServlet {
}
5. Vaadin configuration
@Configuration
@EnableVaadin
public class VaadinConfiguration {}
6. Vaadin widgetset
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.5.1//EN"
"http://google-web-toolkit.googlecode.com/svn/tags/2.5.1/distro-source/core/src/gwt-module.dtd">
<module>
<inherits name="com.vaadin.DefaultWidgetSet"/>
<inherits name="com.vaadin.addon.responsive.ResponsiveWidgetSet" />
</module>
7. WebContextInitializer (web.xml in java config)
public class WebContextInitializer implements WebApplicationInitializer {
@Override
public void onStartup(javax.servlet.ServletContext servletContext) throws ServletException {
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
context.scan(WebContextInitializer.class.getPackage().getName());
servletContext.addListener(new ContextLoaderListener(context));
registerServlet(servletContext);
}
private void registerServlet(ServletContext servletContext) {
ServletRegistration.Dynamic dispatcher = servletContext.addServlet("vaadin", SpringVaadinServlet.class);
dispatcher.setLoadOnStartup(1);
}
}
Switching forward and back between default ("") and register ("register") view doubles the layout on the default view.
Maybe i did something wrong in configuration?