flow icon indicating copy to clipboard operation
flow copied to clipboard

BeforeEnterEvent's rerouteTo doesn't update the URL

Open OlliTietavainenVaadin opened this issue 8 years ago • 7 comments

<vaadin.version>10.0.0.beta10</vaadin.version> Example app: MainView.java

@Route("")
public class MainView extends VerticalLayout implements BeforeEnterObserver {

    @Override
    public void beforeEnter(BeforeEnterEvent event) {
        event.rerouteTo("second");
    }
}

SecondView.java

@Route("second")
public class SecondView extends VerticalLayout {

    public SecondView() {
        add(new Label("hello"));
    }
}

After opening the app at localhost, I see the "hello" label, but the URL is still http://localhost:8080/. I'd expect it to be http://localhost:8080/second

OlliTietavainenVaadin avatar May 28 '18 13:05 OlliTietavainenVaadin

We also have an issue for postponing showing the wrong url #3619, but I don't see why on reroute we would not show the changed url out of the box. @Legioth or @caalador do you recall any specific reason for this or it is just not added ? I think a simple replaceState with the new url should be done.

pleku avatar May 29 '18 07:05 pleku

+1 The issue is still present in 12 beta2. Any plan on when it could be fixed?

gualtierotesta avatar Dec 05 '18 07:12 gualtierotesta

The reroute terminology we're using implies that the URL doesn't change, because there's also rerouteToError for which there isn't even a new URL to change to. rerouteTo(String) means reroute to the view registered for that URL.

Because reroute is meant to route to e.g. login when user is not authenticated, and preserving the URL. There should probably be a forwardTo that would update the url also.

caalador avatar Dec 05 '18 09:12 caalador

@caalador If I understand correctly this is not bug anymore, should be enhancement right?

sahalsaad avatar Dec 08 '18 04:12 sahalsaad

@sahalsaad Yes, that is true. Thanks for the catch. Updated the labels.

caalador avatar Dec 10 '18 06:12 caalador

@caalador What is the acceptance criteria for this ticket? Is it just reroute and update the location?

sahalsaad avatar Dec 10 '18 08:12 sahalsaad

Acceptance Criteria

  • add forwardTo method with the suitable overloads like with rerouteTo and same semantics
    • the URL should be updated, but there should not be another History state entry in the browser -> it needs to use history.replaceState instead of pushState
  • add mention of this to the documentation after https://github.com/vaadin/flow-and-components-documentation/blob/master/documentation/routing/tutorial-routing-lifecycle.asciidoc#reroute as its own subtopic
  • in addition to basic unit tests, there needs to be integration tests for this, similarly to the reroute feature
    • https://github.com/vaadin/flow/blob/master/flow-tests/test-root-context/src/main/java/com/vaadin/flow/uitest/ui/RerouteView.java
    • https://github.com/vaadin/flow/blob/master/flow-tests/test-root-context/src/test/java/com/vaadin/flow/uitest/ui/RerouteIT.java

pleku avatar Dec 11 '18 10:12 pleku