Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Legacy URL fragment lost after navigation #123

Closed
javier-godoy opened this issue Apr 18, 2023 · 1 comment
Closed

Legacy URL fragment lost after navigation #123

javier-godoy opened this issue Apr 18, 2023 · 1 comment
Labels

Comments

@javier-godoy
Copy link

MPR (Vaadin 23.3.6/7.7.38) with MprNavigatorRoute. Chrome 111.

There are two legacy views. After navigation from http://127.0.0.1:8080/#!view1 to http://127.0.0.1:8080/#!view2, the target URL is visible for a split second, then the URL reverts to http://127.0.0.1:8080/

mpr

@Route("")
public class MyNavigatorRoute extends MprNavigatorRoute {
    @Override
    public void configureNavigator(Navigator navigator) {
      navigator.addView("view1", View1.class);
      navigator.addView("view2", View2.class);
    }
}


public class View1 extends VerticalLayout implements View {

  @Override
  public void enter(ViewChangeEvent event) {}
  
  public View1() {
    setCaption("View 1");
    addComponent(new Button("Navigate", ev -> {
      getUI().getNavigator().navigateTo("view2");
    }));
  }
  
}

public class View2 extends VerticalLayout implements View {

  @Override
  public void enter(ViewChangeEvent event) {}
  
  public View2() {
    setCaption("View 2");
  }
  
}
@tltv
Copy link
Member

tltv commented May 2, 2023

Tried this out and this is not an issue with Vaadin 8. Vaadin 7 clears the state after a small delay. Bug in Vaadin 7 navigator maybe. I wonder if its known issue even without MPR.

Workaround is to run a Javascript snippet in enter(ViewChangeEvent) to update state with window.history.pushState.

@Override
public void enter(ViewChangeEvent event) {
	if(!Objects.equals(event.getOldView(), this)) {
		event.getNavigator().getUI().getPage().getJavaScript().execute(
				"setTimeout(() -> window.history.pushState('" + event.getViewName() + "', '', ''))");
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants