0

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?

alexanoid
  • 24,051
  • 54
  • 210
  • 410

1 Answers1

1

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.

Simon Martinelli
  • 34,053
  • 5
  • 48
  • 82
  • 1
    Thank you! I invoked this logic from incorrect context(from Spring bean from my service layer). It doesn't work there. But directly from Vaadin button click handler it works perfectly! Thanks again for your help! – alexanoid Jul 27 '22 at 13:48
  • 1
    In that case UI.getCurrent().getPage().fetchCurrentURL(System.out::println); would work too ;-) – Simon Martinelli Jul 27 '22 at 13:51