Add new API to Page for accessing the location as shown in the browser's address bar. Some things to take into account:
null or only an approximation before the value has been verified from the browser.java.net.URI for tracking the location, but this is not optimal since there are some weird cases that browsers accept but the URI class rejects.Setting might be different with all the side effects, but getting the page current URL is very typical scenario in application code. Similar API approach than page title sound most intuitive.
We are also missing Page.setLocation(String url) & Page.reload() or similar, which is necessary in lots of cases, like after logging out from the App.
Current workaround is to use e.g. Page.executeJavaScript("window.location.href = 'myurl'); but this cumbersome.
Page.reload() is in #3299
To implement this feature Page.getLocation() could just use this:
public static URI getLocation(){
VaadinServletRequest request = (VaadinServletRequest) VaadinService.getCurrentRequest();
StringBuffer uriString = request.getRequestURL();
return new URI(uriString.toString());
}
@gsedlacz. That approach works during initial rendering, but not from a background thread (where there is no current request) nor for incremental update requests since the URL of those are always the common XHR handler endpoint location and not the location that the browser is navigated to.
In 2.x versions, there is still the internal API https://vaadin.com/api/platform/14.1.3/com/vaadin/flow/server/VaadinServlet.html#getApplicationUrl-HttpServletRequest- which constructs the URL based on what was in the given request.
..but as described in the issue description, the URL might be different due to a frontend proxy, thus the JS window.location.href would be most reliable, and that could be now fetched using a Page.executeJs that provides a PendingJavaScriptResult since 2.0.
As for the use case described in #1894, there would be a need for keeping the "updated" value for saving it when a logout happens, and for that it could be sufficient to have a getInitialPageLocation() in ExtendedClientResponse and then another method in Page which would combine that to the latest routing changes, to be available immediately without a roundtrip for the logout usage.
Still relevant. Do we have a clear use case to base the implementation? Is this something Router solves?
Logically, getting the page title is similar case:
https://vaadin.com/forum/thread/17979510/tip-how-to-get-page-title-and-view-of-current-page
I could be wrong, but this kinda looks like (just another way of approaching it / could be a part of)
All three tickets (including this one) are in the top 30 upvoted open tickets in flow.
PageExtendedClientDetails is not documented at the moment)window.location.href will probably never be removed and we have ITs JS execution feature, only an unit test is needed
Most helpful comment
Still relevant. Do we have a clear use case to base the implementation? Is this something Router solves?
Logically, getting the page title is similar case:
https://vaadin.com/forum/thread/17979510/tip-how-to-get-page-title-and-view-of-current-page