BeforeEnterEvent's rerouteTo doesn't update the URL
<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
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.
+1 The issue is still present in 12 beta2. Any plan on when it could be fixed?
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 If I understand correctly this is not bug anymore, should be enhancement right?
@sahalsaad Yes, that is true. Thanks for the catch. Updated the labels.
@caalador What is the acceptance criteria for this ticket? Is it just reroute and update the location?
Acceptance Criteria
- add
forwardTomethod with the suitable overloads like withrerouteToand same semantics- the URL should be updated, but there should not be another History state entry in the browser -> it needs to use
history.replaceStateinstead ofpushState
- the URL should be updated, but there should not be another History state entry in the browser -> it needs to use
- 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