Search code examples
vaadinvaadin23

Vaadin23 how to get the current application url


Looks like previously it was possible to get the current location url (url in the browser location bar) by Page.getCurrent().getLocation();

How to get the current application url in Vaadin23? Is it possible with com.vaadin.flow.component.UI object?

I tried

UI.getCurrent().getPage().fetchCurrentURL(currentUrl -> {
   System.out.println("!!!: " + currentUrl);
});

but this callback is never invoked.. What am I doing wrong?


Solution

  • I always use JavaScript:

    UI.getCurrent().getPage()
                .executeJs("return window.location.href")
                .then(jsonValue -> System.out.println(jsonValue.asString()));
    

    But

    UI.getCurrent().getPage().fetchCurrentURL(System.out::println);
    

    does the same internally.